Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User
- {
- public static function checkUser($password, $passwordDb, $username)
- {
- global $dbh;
- if (substr($passwordDb, 0, 1) == "$")
- {
- if (password_verify($password, $passwordDb))
- {
- return true;
- }
- return false;
- }
- else
- {
- $passwordBcrypt = self::hashed($password);
- if (md5($password) == $passwordDb)
- {
- $stmt = $dbh->prepare("UPDATE users SET password = :password WHERE username = :username");
- $stmt->bindParam(':username', $username);
- $stmt->bindParam(':password', $passwordBcrypt);
- $stmt->execute();
- return true;
- }
- return false;
- }
- }
- public static function hashed($password)
- {
- return password_hash($password, PASSWORD_BCRYPT);
- }
- public static function validName($username)
- {
- if(strlen($username) <= 12 && strlen($username) >= 3 && ctype_alnum($username))
- {
- return true;
- }
- return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement