當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Password::Encryption方法代碼示例

本文整理匯總了PHP中Password::Encryption方法的典型用法代碼示例。如果您正苦於以下問題:PHP Password::Encryption方法的具體用法?PHP Password::Encryption怎麽用?PHP Password::Encryption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Password的用法示例。


在下文中一共展示了Password::Encryption方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: adminLogin

 public function adminLogin($username, $admin_name = '', $remember = false)
 {
     $admin_info = $this->admin_model->getAdminByUsername($username);
     $auth_list = array();
     if (empty($admin_info)) {
         $now_time = time();
         $password = Password::Encryption($username, mt_rand(100000, 9999999999));
         //密碼加密
         $admin_data = array('username' => $username, 'admin_name' => $admin_name, 'password' => $password, 'department_id' => 0, 'last_login' => $now_time, 'error_times' => 0, 'error_date' => Star_Date::getDate(), 'add_time' => $now_time, 'update_time' => $now_time);
         $admin_id = $this->admin_model->insert($admin_data);
         $admin_info = $this->admin_model->getAdminById($admin_id);
     } else {
         $admin_data = array('last_login' => time());
         $admin_id = $admin_info['admin_id'];
         $this->updateAdmin($admin_info['admin_id'], $admin_data);
     }
     $admin_login_data = array('admin_id' => $admin_id, 'login_ip' => ip2long(Star_Http_Request::getIp()), 'add_time' => time());
     $admin_login_model = new AdminLoginModel();
     $admin_login_model->insert($admin_login_data);
     //添加登錄記錄
     //返回部門權限
     $department_auth = $this->auth_model->getAuthByDepartment($admin_info['department_id']);
     //返回管理員權限
     $admin_auth = $this->auth_model->getAuthByAdmin($admin_info['admin_id']);
     if ($department_auth) {
         foreach ($department_auth as $auth) {
             $menu_id = $auth['menu_id'];
             $controller = $auth['controller'];
             $action = $auth['action'];
             $auth_list[$menu_id] = $this->getUrl($controller, $action);
         }
     }
     if ($admin_auth) {
         foreach ($admin_auth as $auth) {
             $menu_id = $auth['menu_id'];
             $controller = $auth['controller'];
             $action = $auth['action'];
             $auth_list[$menu_id] = $this->getUrl($controller, $action);
         }
     }
     $auth_token = $this->makeAuthSign($auth_list);
     $token = $this->makeLoginSign($admin_info['admin_id'], $admin_info['username'], $admin_info['department_id'], $admin_info['last_login'], $auth_token);
     $admin_data = array('admin_id' => $admin_info['admin_id'], 'department_id' => $admin_info['department_id'], 'username' => $admin_info['username'], 'last_login' => $admin_info['last_login'], 'token' => $token, 'auth_token' => $auth_token, 'admin_name' => $admin_info['admin_name']);
     $this->setLoginInfo($admin_data, $remember);
     //設置用戶登錄信息
     Star_Cookie::set('auth', base64_encode(json_encode($auth_list)), time() + 86400 * 30, '/', '', false, true);
     //設置用戶權限信息
 }
開發者ID:hwsyy,項目名稱:php-management-system,代碼行數:48,代碼來源:AdminService.php

示例2: loginAction

 /**
  * 管理員登錄 
  */
 public function loginAction()
 {
     $request = $this->getRequest();
     $admin_service = new AdminService();
     //用戶已登錄跳轉到後台首頁
     if ($admin_service->checkLogin() == true) {
         return $this->redirect('/admin');
     }
     if ($request->isPost()) {
         $username = trim($request->getParam('username'));
         $password = $request->getParam('password');
         $captcha = $request->getParam('captcha');
         $remember = $request->getParam('remember');
         if (empty($username)) {
             return $this->showJson(1, '請輸入用戶名');
         }
         if (empty($password) || strlen($password) < 6) {
             return $this->showJson(2, '請輸入6位以上密碼');
         }
         if ($admin_service->checkCaptcha($captcha) == false) {
             return $this->showJson(3, '帳號或密碼有誤,請重新輸入');
         }
         $admin = $admin_service->getAdminByUsername($username);
         if (empty($admin)) {
             return $this->showJson(403, '帳號或密碼有誤,請重新輸入');
         }
         //當天密碼錯誤超過500次
         if ($admin['error_times'] > 500) {
             return $this->showJson(4, '帳號密碼輸入錯誤次數過多,請明日再試。');
         }
         //驗證密碼是否正確
         if ($admin['password'] == Password::Encryption($username, $password)) {
             $admin_service->adminLogin($username, '', $remember);
         } else {
             $admin_data = array();
             if (Star_Date::getDate() == $admin['error_date']) {
                 $admin_data = array('error_date' => Star_Date::getDate(), 'error_times' => 'error_times + 1');
             } else {
                 $admin_data = array('error_date' => Star_Date::getDate(), 'error_times' => 1);
             }
             $admin_service->updateAdmin($admin['admin_id'], $admin_data, false);
             return $this->showJson(403, '帳號或密碼有誤,請重新輸入');
         }
         return $this->showJson(0, '登錄成功');
     }
 }
開發者ID:hwsyy,項目名稱:php-management-system,代碼行數:49,代碼來源:AdminController.php

示例3: editadminAction

 /**
  * 編輯管理員
  */
 public function editadminAction()
 {
     $request = $this->getRequest();
     $admin_service = new AdminService();
     $admin_id = (int) $request->getParam('admin_id');
     $admin_info = $admin_service->getAdminById($admin_id);
     if (empty($admin_info)) {
         return $this->showWarning('對不起,管理員不存在', '/system/adminmanage');
     }
     if ($request->isPost()) {
         $username = Star_String::escape($request->getParam('username'));
         $admin_name = Star_String::escape($request->getParam('admin_name'));
         $department_id = (int) $request->getParam('department_id');
         $password = $request->getParam('password');
         if ($password && Star_String::strLength($password) < 6) {
             return $this->showWarning('對不起,密碼不能少於6個字符。');
         }
         if (empty($username)) {
             return $this->showWarning('對不起,用戶名不能為空。');
         }
         $admin_data = array('admin_name' => $admin_name, 'department_id' => $department_id, 'update_time' => time());
         $password && ($admin_data['password'] = Password::Encryption($username, $password));
         $rs = $admin_service->updateAdmin($admin_id, $admin_data);
         if ($rs) {
             $admin_service->deleteAuth('admin_id = ' . (int) $admin_info['admin_id']);
             //刪除用戶權限
             $menu_ids = $request->getParam('menu_ids');
             if (!empty($menu_ids)) {
                 $menu_ids = array_unique($menu_ids);
                 foreach ($menu_ids as $menu_id) {
                     $auth_data = array('menu_id' => (int) $menu_id, 'department_id' => 0, 'admin_id' => $admin_id, 'add_time' => time(), 'update_time' => time());
                     //添加權限
                     $admin_service->insertAuth($auth_data);
                 }
             }
             return $this->showWarning('恭喜您,修改成功。', '/system/adminmanage');
         } else {
             return $this->showWarning('很遺憾,修改失敗。');
         }
     }
     $departments = $admin_service->getDepartmentOption();
     $menus = $admin_service->getAllSortMenu();
     //返回所有菜單
     $department_auth_options = $admin_service->getDepartmentAuthOption($admin_info['department_id']);
     //返回部門所有權限
     $admin_auth_options = $admin_service->getAdminAuthOption($admin_info['admin_id']);
     $this->view->assign(array('admin' => $admin_info, 'departments' => $departments, 'menus' => $menus, 'department_auth_options' => $department_auth_options, 'admin_auth_options' => $admin_auth_options));
     $this->render('admininfo');
 }
開發者ID:hwsyy,項目名稱:php-management-system,代碼行數:52,代碼來源:SystemController.php


注:本文中的Password::Encryption方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。