Example #1
0
 public function testPassword()
 {
     $password = \SecureFuncs\SecureFuncs::randomString(32);
     $hash = \SecureFuncs\SecureFuncs::password_hash($password);
     $this->assertInternalType('string', $hash);
     $this->assertTrue(\SecureFuncs\SecureFuncs::password_verify($password, $hash));
 }
Example #2
0
 /**
  * @param $password
  * @param $repeat_password
  * @param $code
  * @return bool
  */
 public function changeForgotPassword($password, $repeat_password, $code)
 {
     // get user attached to code
     $get_user = $this->newBuilder()->select('*')->from('users')->where('forgotpassword_code = :code')->setParameter(':code', $code)->execute();
     if ($get_user->rowcount() === 1) {
         // fetch results
         $user_data = $get_user->fetch();
         // verify entered passwords
         if (empty($password) || empty($repeat_password)) {
             $this->setMessage('error', ADVANCEDLOGINSCRIPT_REGISTER_EMPTY_PASSWORDS);
         } elseif ($password !== $repeat_password) {
             $this->setMessage('error', ADVANCEDLOGINSCRIPT_REGISTER_BOTH_PASSWORDS_SAME);
         } elseif (strlen($password) < 8) {
             $this->setMessage('error', ADVANCEDLOGINSCRIPT_REGISTER_SHORT_PASSWORDS);
         } else {
             // Hash the new password
             $password_hash = \SecureFuncs\SecureFuncs::password_hash($password);
             // Update the database
             $update_user = $this->newBuilder()->update('users')->set('password', ':password')->setParameter('password', $password_hash)->set('forgotpassword_code', 'NULL')->set('forgotpassword_created', 'NULL')->where('id = :id AND forgotpassword_code = :code')->setParameter('id', $user_data['id'])->setParameter('code', $code)->execute();
             if ($update_user === 1) {
                 $this->setMessage('success', ADVANCEDLOGINSCRIPT_USER_PASSWORD_UPDATE);
                 return true;
             } else {
                 $this->setMessage('error', ADVANCEDLOGINSCRIPT_USER_PASSWORD_UPDATE_FAIL);
             }
         }
     }
     return false;
 }