コード例 #1
0
 public function authenticate()
 {
     $users = array('demo' => 'demo', 'admin' => 'admin');
     $user = Users::model()->findByAttributes(array('user_id' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!bCrypt::verify($this->password, $user->password)) {
             //            $pass = $user->password;
             //            $pass2 = $this->password;
             //            $very = $this->encrypt($this->password);
             //            $encrypt = $this->encrypt("nove");
             //            $enc = NEW bCrypt();
             //            $veryvied = $enc->verify($this->password, $user->password);
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $user->id;
             $this->username = $user->user_id;
             //$this->username = '******';
             $this->errorCode = self::ERROR_NONE;
             $user->last_visit_date = get_date_today('yyyy-MM-dd HH:mm:ss');
             $user->save();
         }
     }
     return !$this->errorCode;
 }
コード例 #2
0
 public function authenticate()
 {
     $user = $this->_user = User::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif (!bCrypt::verify($this->password, $user->password)) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } elseif ($user->is_deleted) {
         $this->errorCode = self::ERROR_USER_IS_DELETED;
     } else {
         $this->_id = $user->id;
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }
コード例 #3
0
 public function actionUpdatePass()
 {
     if (!Yii::app()->request->isAjaxRequest) {
         return;
     }
     if (isset($_POST) && !empty($_POST)) {
         $passold = $_POST['passwordold'];
         $passnew = $_POST['password'];
         $model = $this->loadModel(Yii::app()->user->getId(), 'Users');
         $msg = "Password lama salah. Untuk mengganti password, password lama harus benar.";
         $status = false;
         if (bCrypt::verify($passold, $model->password)) {
             //                $crypt = new bCrypt();
             //                $pass = $crypt->hash($passnew);
             $model->password = $passnew;
             if ($model->save()) {
                 $status = true;
                 $msg = "Password berhasil diganti.";
             } else {
                 $status = false;
                 $msg = "Password gagal diganti";
             }
         }
         echo CJSON::encode(array('success' => $status, 'msg' => $msg));
         Yii::app()->end();
     }
 }