示例#1
0
文件: CryptTest.php 项目: phpscr/usvn
 public function testCrypt()
 {
     $crypt = USVN_Crypt::crypt("toto");
     $this->assertTrue(USVN_Crypt::checkPassword("toto", $crypt));
     $this->assertFalse(USVN_Crypt::checkPassword("tutu", $crypt));
     $crypt = '$apr1$A.IgA/..$vcK1pKAvkEGvAT0ob46Bw0';
     $this->assertTrue(USVN_Crypt::checkPassword("toto", $crypt));
 }
示例#2
0
 protected function getUserData($data)
 {
     if (!isset($data['users_lastname']) || !isset($data['users_firstname']) || !isset($data['users_email']) || !isset($data['users_password']) || !isset($data['users_new_password']) || !isset($data['users_new_password_copy'])) {
         return array();
     }
     $user = $this->getUser();
     if (!USVN_Crypt::checkPassword($data['users_password'], $user->password)) {
         throw new USVN_Exception(T_("Wrong password"));
     }
     if (!empty($data['users_new_password']) && !empty($data['users_new_password_copy'])) {
         if ($data['users_new_password'] !== $data['users_new_password_copy']) {
             throw new USVN_Exception(T_('Not the same password.'));
         }
         $data['users_password'] = $data['users_new_password'];
     }
     $user = array('users_lastname' => $data['users_lastname'], 'users_firstname' => $data['users_firstname'], 'users_email' => $data['users_email'], 'users_password' => $data['users_password']);
     return $user;
 }
示例#3
0
文件: Database.php 项目: phpscr/usvn
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $result = array();
     $result['isValid'] = false;
     $result['identity'] = array();
     $result['identity']['username'] = $this->_login;
     $result['messages'] = array();
     $table = new USVN_Db_Table_Users();
     $user = $table->fetchRow(array('users_login = ?' => $this->_login));
     if ($user === NULL) {
         $result['messages'][] = sprintf(T_('Login %s not found'), $this->_login);
         return new Zend_Auth_Result($result['isValid'], $result['identity'], $result['messages']);
     }
     if (!USVN_Crypt::checkPassword($this->_password, $user->password)) {
         $result['messages'][] = T_('Incorrect password');
         return new Zend_Auth_Result($result['isValid'], $result['identity'], $result['messages']);
     }
     $result['isValid'] = true;
     return new Zend_Auth_Result($result['isValid'], $result['identity'], $result['messages']);
 }
示例#4
0
文件: UsersTest.php 项目: phpscr/usvn
 public function testUserUpdateInvalidPassword()
 {
     $table = new USVN_Db_Table_Users();
     $obj = $table->fetchNew();
     $obj->setFromArray(array('users_login' => 'UpdateInvalidPassword', 'users_password' => 'password', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     $id = $obj->save();
     $obj = $table->find($id)->current();
     $obj->setFromArray(array('users_login' => 'UpdateInvalidPassword', 'users_password' => 'badPass', 'users_firstname' => 'firstname', 'users_lastname' => 'lastname', 'users_email' => '*****@*****.**'));
     try {
         $obj->save();
     } catch (USVN_Exception $e) {
         $this->assertContains('Password incorrect', $e->getMessage());
         return;
     }
     $user = $table->fetchRow(array('users_login = ?' => 'UpdateInvalidPassword'));
     $this->assertTrue(USVN_Crypt::checkPassword('password', $user->password));
 }