Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region login only
- public function receive_password($username){
- //get hashed password 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 $userInfo->UPass;
- }
- }else{
- //error spotted make sure to close just in case
- //close the connection
- $con = null;
- die("Error: No users found!");
- }
- }
- public function receive_salt($username){
- //get the salt 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 $userInfo->USalt;
- }
- }else{
- //error spotted make sure to close just in case
- //close the connection
- $con = null;
- die("Error: No users found!");
- }
- }
- public function equal_password($username, $password){
- //check if the passwords matches
- $password = $this->create_hashed_password($password, $this->receive_salt($username)); //creates the hashed password from the given password using the DB salt
- $hashedPassword = $this->receive_password($username); //receives the hashed password from the database through the "receive_passworrd function"
- if($password == $hashedPassword){
- return true;
- }else{
- return false;
- }
- }
- #end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement