Esempio n. 1
0
function validationHook()
{
    global $db, $row, $result, $MAX_RESERVED_ID, $dtm;
    $dtm = date('Y-m-d H:i:s');
    if ($row->first_name == '' && $row->last_name == '') {
        if (!isset($result->fieldErrors['first_name'])) {
            $result->fieldErrors['first_name'] = "First Name or Last Name is required.\n";
        }
    }
    $row->password_hash = '';
    $password = isset($row->password) ? $row->password : '';
    $reEnterPassword = isset($row->reEnterPassword) ? $row->reEnterPassword : '';
    if ($password != '') {
        if ($reEnterPassword != $password) {
            if (!isset($result->fieldErrors['password'])) {
                $result->fieldErrors['password'] = "******";
            }
        } else {
            if (strlen($password) < getMinPasswordLength()) {
                if (!isset($result->fieldErrors['password'])) {
                    $result->fieldErrors['password'] = sprintf("Password must be at least %d characters.\n", getMinPasswordLength());
                }
            } else {
                if (!isValidPassword($password)) {
                    $result->fieldErrors['password'] = "******";
                } else {
                    $saltchrs = '0123456789abcdefghijklmnopqrstuvwxyz';
                    $salt = '';
                    for ($i = 0; $i < 31; $i++) {
                        $salt .= $saltchrs[mt_rand(0, strlen($saltchrs) - 1)];
                    }
                    $row->password_hash = hash('sha512', $password . '{' . $salt . '}') . '{' . $salt . '}';
                }
            }
        }
    } else {
        if ($row->id <= 0) {
            $result->fieldErrors['password'] = "******";
        }
    }
}
Esempio n. 2
0
 function isValidPassword($password)
 {
     if (strlen($password) < getMinPasswordLength()) {
         return false;
     }
     $haveAlpha = $haveDigit = false;
     for ($i = 0; $i < strlen($password); $i++) {
         $c = $password[$i];
         if (ctype_alpha($c)) {
             $haveAlpha = true;
         } else {
             if (ctype_digit($c)) {
                 $haveDigit = true;
             } else {
                 if (!ctype_punct($c)) {
                     return false;
                 }
             }
         }
     }
     return $haveAlpha && $haveDigit ? true : false;
 }