<?php

require_once 'classes/CheckPassword.php';
$usernameMinChars = 6;
$errors = array();
if (strlen($username) < $usernameMinChars) {
    $errors[] = "Username must be at least {$usernameMinChars} characters.";
}
if (preg_match('/\\s/', $username)) {
    $errors[] = 'Username should not contain spaces.';
}
$checkPwd = new Ps2_CheckPassword($password, 10);
$checkPwd->requireMixedCase();
$checkPwd->requireNumbers(2);
$checkPwd->requireSymbols();
$passwordOK = $checkPwd->check();
if (!$passwordOK) {
    $errors = array_merge($errors, $checkPwd->getErrors());
}
if ($password != $retyped) {
    $errors[] = "Your passwords don't match.";
}
if (!$errors) {
    // include the connection file
    require_once 'connection.php';
    $conn = dbConnect('write');
    // create a salt using the current timestamp
    $salt = time();
    //encrypt the password and salt
    $pwd = sha1($password . $salt);
    //prepare sql statement
예제 #2
0
<?php

require_once "{$path2root}/assets/classes/CheckPassword.php";
$errors = array();
$checkPwd = new Ps2_CheckPassword($password, 6);
//$checkPwd->requireMixedCase();
//$checkPwd->requireNumbers();
//$checkPwd->requireSymbols();
$passwordOK = $checkPwd->check();
if (!$passwordOK) {
    $errors = array_merge($errors, $checkPwd->getErrors());
}
if ($password != $retyped) {
    $errors[] = "<div class=\"alert alert-error\"><a class=\"close\" data-dismiss=\"alert\" href=\"#\">&times;</a>Your passwords don't match.</div>";
}
if (!$errors) {
    // include the connection file
    require_once 'connection.inc.php';
    $conn = dbConnect('write');
    // create a salt using the current timestamp
    $salt = time();
    // encrypt the password and salt with SHA1
    $pwd = sha1($password . $salt);
    // prepare SQL statement
    $sql = 'INSERT INTO users (salt, pwd)
          VALUES (?, ?)';
    $stmt = $conn->stmt_init();
    $stmt = $conn->prepare($sql);
    // bind parameters and insert the details into the database
    $stmt->bind_param('is', $salt, $pwd);
    $stmt->execute();