Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class functions{
- #region main
- #region username related
- public function check_username($username){
- $length = new stdClass();
- $length->min = 4;
- $length->max = 10;
- $length->username = strlen($username);
- if($length->username >= $length->min && $length->username <= $length->max){
- return ctype_alnum($username);
- }else{
- return false;
- }
- }
- public function username_exists($username){
- //get the username from the database
- global $dbhost, $dbusername, $dbpassword, $dbname;
- $con = new Database($dbhost, $dbusername, $dbpassword, $dbname);
- $query = $con->runQuery("SELECT * FROM `users` WHERE `username`='".$username."'");
- if($query->rowCount() != 0){
- while($row_info = $query->fetch(PDO::FETCH_ASSOC)){
- $userInfo = new stdClass();
- $userInfo->UID = $row_info['ID'];
- $userInfo->UName = $row_info['username'];
- $userInfo->UPass = $row_info['password'];
- $userInfo->USalt = $row_info['salt'];
- //userInfo is succesfully loaded!
- //close the connection
- $con = null;
- //return the password!
- return true;
- }
- }else{
- //error spotted make sure to close just in case
- //close the connection
- $con = null;
- return false;
- }
- }
- #end
- #region password related
- public function check_password($password){
- $length = new stdClass();
- $length->min = 6;
- $length->max = 20;
- $regex = '/^[a-zA-Z0-9 \!\@\#\$\%\^\&\*]{'.$length->min.','.$length->max.'}$/';
- if(preg_match($regex, $password)){
- return true;
- }else{
- return false;
- }
- }
- public function create_hashed_password($password, $salt){
- $blowFishSalt = '$2y$12$'.$salt.'$';
- return(crypt($password.$salt,$blowFishSalt));
- }
- #end
- #end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement