Advertisement
Guest User

Untitled

a guest
May 18th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Created by PhpStorm.
  5.  * User: ehiag
  6.  * Date: 5/17/2016
  7.  * Time: 3:53 AM
  8.  */
  9.  
  10. require_once('../thirdparty/PasswordLib/bootstrap.php');
  11.  
  12. use PasswordLib\PasswordLib as passwordLib;
  13.  
  14. class password
  15. {
  16.     public $cost = 8 ;//4 to 31
  17.  
  18.     public $algo;
  19.  
  20.     private $passwordLib;
  21.  
  22.    
  23.  
  24.  
  25.     public function __construct()
  26.     {
  27.         $this->algo = '$2y$'; // prefix for PASSWORD_BCRYPT
  28.  
  29.         $this->passwordLib = new passwordLib();
  30.  
  31.     }
  32.  
  33.  
  34.  
  35.     public function create_password_hash($password)
  36.     {
  37.             $pass = trim($password);
  38.             $hash = $this->passwordLib->createPasswordHash($pass,$this->algo,array('cost'=>$this->cost)); //create the hash of the user-supplied password
  39.             return $hash;
  40.     }
  41.  
  42.     public function password_verify($password,$hash)
  43.     {
  44.             $is_valid = $this->passwordLib->verifyPasswordHash($password, $hash);
  45.             if ($is_valid){
  46.                 return true;
  47.             }else{
  48.                 return false;
  49.             }
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement