当前位置: 首页>>代码示例>>PHP>>正文


PHP SHA1函数代码示例

本文整理汇总了PHP中SHA1函数的典型用法代码示例。如果您正苦于以下问题:PHP SHA1函数的具体用法?PHP SHA1怎么用?PHP SHA1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SHA1函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addDream

 /**
  * Resizes/resamples an image uploaded via a web form
  *
  * @param array $upload the array contained in $_FILES
  * @param bool $rename whether or not the image should be renamed
  * @return string the path to the resized uploaded file
  */
 public function addDream($d, $img = NULL)
 {
     // Sanitize the data and store it in variables
     $dreamName = htmlentities(strip_tags($d['dreamName']), ENT_QUOTES);
     $dreamContent = htmlentities(strip_tags($d['dreamContent']), ENT_QUOTES);
     // Keep formatting of comments and remove extra whitespace
     $dreamContent = nl2br(trim($dreamContent));
     if (!empty($_POST['id'])) {
         $sql = "UPDATE dreams\n             SET dreamName=?, dreamContent=?, url=?\n             WHERE id=?\n             LIMIT 1";
         $q = $this->db->prepare($sql);
         $q->execute(array($dreamName, $dreamContent, $url = $this->makeURL($dreamName), $_POST['id']));
         $q->closeCursor();
         return $url;
     } else {
         $sql = "INSERT INTO dreams (id, dreamName, dreamContent, image, tag, url, username)\n              VALUES (?, ?, ?, ?, ?, ?, ?)";
         $q = $this->db->prepare($sql);
         $q->execute(array($id = SHA1(uniqid()), $dreamName, $dreamContent, $img, $tags = 'General', $url = $this->makeURL($dreamName), $username = 'Harrmalik'));
         $q->closeCursor();
         // Get the ID of the entry we just saved
         $id_obj = $this->db->query("SELECT LAST_INSERT_ID()");
         $id = $id_obj->fetch();
         $id_obj->closeCursor();
         return $id_obj;
     }
 }
开发者ID:Harrmalik,项目名称:get-lucid,代码行数:32,代码来源:dreams.inc.php

示例2: addAccount

 /**
  *
  *	fungsi AddAccount
  *	adalah fungsi yang digunakan untuk menambah account ke dalam database
  *	@param void
  *	@return void
  */
 function addAccount()
 {
     //set all variable needed to do validation
     $this->form_validation->set_rules('username', 'Username', 'required|alpha_numeric');
     $this->form_validation->set_rules('password', 'Password', 'required');
     $this->form_validation->set_rules('telp', 'No telp', 'required|numeric');
     $this->form_validation->set_rules('name', 'Nama', 'required|alpha');
     $this->form_validation->set_rules('address', 'Alamat', 'alpha_numeric');
     //handle invalid validation
     if ($this->form_validation->run() == FALSE) {
         $m_data['notification_message'] = "Masukan tidak valid";
     } else {
         //get all variable post
         $username = $this->input->get_post('username');
         $password = $this->input->get_post('password');
         $role_name = $this->input->get_post('jabatan');
         $nama = $this->input->get_post('name');
         $nohp = $this->input->get_post('telp');
         $alamat = $this->input->get_post('address');
         //create account in account model
         $this->account_model->create_account($username, SHA1($password), $role_name, $nama, $alamat, $nohp);
         $m_data['notification_message'] = "Account berhasil dibuat";
     }
     $h_data['style'] = "simpel-herbal.css";
     $f_data['author'] = "fasilkom 07";
     $this->load->view('admin/header.php', $h_data);
     $this->load->view('account/add.php', $m_data);
     $this->load->view('admin/footer.php', $f_data);
 }
开发者ID:bejo4ever,项目名称:sijambu,代码行数:36,代码来源:add_controller.php

示例3: login

 function login()
 {
     $referer = isset($_POST['referer']) ? $_POST['referer'] : _BASE_URL_ . "/posts/view_all";
     if (!trim($_POST['user_id']) || !trim($_POST['password'])) {
         msg_page("Required fields are missing.");
     }
     $data = array("user_id" => trim(strval($_POST['user_id'])), "password" => SHA1($_POST['password'] . SALT));
     $user = $this->User->getUser("*", $data);
     if ($this->User->count > 0) {
         $_SESSION['LOGIN_NO'] = $user["id"];
         $_SESSION['LOGIN_ID'] = $user["user_id"];
         $_SESSION['LOGIN_NAME'] = $user["name"];
         $_SESSION['LOGIN_EMAIL'] = $user["email"];
         $_SESSION['LOGIN_LEVEL'] = $user["level"];
         /*check is save id */
         $is_save_id = isset($_POST['is_save_id']) ? trim(strval($_POST['is_save_id'])) : "N";
         if ($is_save_id == "Y") {
             setcookie("is_save_id", "Y", time() + 60 * 60 * 24 * 365, "/");
             setcookie("LOGIN_ID", $user['user_id'], time() + 60 * 60 * 24 * 365, "/");
         } else {
             setcookie("is_save_id", "", time() + 60 * 60 * 24 * 365, "/");
         }
     } else {
         msg_page("information does not match.", $referer);
     }
     redirect($referer);
 }
开发者ID:guruahn,项目名称:gjboard,代码行数:27,代码来源:userscontroller.php

示例4: authenticate

 /**
  * Authenticates a user.	 
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $user = User::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         // No user found!
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->password !== SHA1($this->password)) {
             // Invalid password!
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             // Okay!
             if (!$user->admin) {
                 $ARData = DeviceUser::model()->with('device')->findAllByAttributes(array('user_id' => $user->id));
                 $devices = CHtml::listData($ARData, 'device_id', 'device.reference');
                 $menu = array();
                 $mydevices = array();
                 foreach ($devices as $id => $name) {
                     $menu[] = array('label' => $name, 'url' => '/client/status/' . $id);
                     $mydevices[] = $id;
                 }
                 $this->setState('clientMenu', $menu);
                 $this->setState('devices', $mydevices);
             }
             $this->setState('isAdmin', $user->admin ? true : false);
             $this->_id = $user->id;
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
开发者ID:dailos,项目名称:heimdal,代码行数:35,代码来源:UserIdentity.php

示例5: authenticate

 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $user = User::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->password !== SHA1($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->errorCode = self::ERROR_NONE;
             $this->id = $user->id;
             $this->setState('isAdmin', $user->admin == 1);
             $auth = Yii::app()->authManager;
             // Initialize Auth Manager
             // Clear all previously set roles (from previous logins w/o logout)
             foreach ($auth->getAuthItems(2, $this->id) as $authItem) {
                 $auth->revoke($authItem->name, $this->id);
             }
             if ($user->admin == 1) {
                 $auth->assign(UserIdentity::ROLE_ADMIN, $this->id);
             } else {
                 $auth->assign(UserIdentity::ROLE_USER, $this->id);
             }
             // Save new roles to auth manager
             Yii::app()->authManager->save();
         }
     }
     return !$this->errorCode;
 }
开发者ID:vitaliy7711,项目名称:pdnsops,代码行数:33,代码来源:UserIdentity.php

示例6: authenticate

 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $user = User::model()->findByAttributes(array('email' => $this->username));
     if ($user === null) {
         // No user found!
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($user->password !== SHA1($this->password)) {
             // Invalid password!
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($user->active == 0) {
                 // Invalid password!
                 $this->errorCode = self::ERROR_ACTIVATION;
             } else {
                 // Okay!
                 $this->errorCode = self::ERROR_NONE;
                 // Store the role (user or admin) in a session:
                 $this->setState('role', $user->role);
                 $this->_id = $user->ID;
             }
         }
     }
     return !$this->errorCode;
 }
开发者ID:FranHurtado,项目名称:traza,代码行数:33,代码来源:UserIdentity.php

示例7: encryptSha1

 /**
  * Encrypts a string to SHA1 format using a salt
  * 
  * @param	: $salt (string)
  * @param	: $password (string)
  * @return	: $encrypted (string)
  */
 public function encryptSha1($salt, $password)
 {
     $salt = strtoupper($salt);
     $password = strtoupper($password);
     $encrypted = SHA1($salt . ':' . $password);
     return $encrypted;
 }
开发者ID:heros,项目名称:PhentomCMS,代码行数:14,代码来源:class.common.php

示例8: criaProtocolo

 /**
  * Cria um novo protocolo
  * @param int $iTipo
  * @param string $sMensagem
  * @param null $sCaminhoSistema
  * @throws Exception
  */
 public function criaProtocolo($iTipo = 3, $sMensagem, $sCaminhoSistema = NULL)
 {
     if (!$sMensagem) {
         throw new Exception('Informe uma mensagem!');
     }
     if (empty(self::$aTiposProtocolo[$iTipo])) {
         throw new Exception('Tipo de Protocolo está inválido!');
     }
     try {
         /**
          * Monta a rota executada pelo sistema
          */
         if (empty($sCaminhoSistema)) {
             $sSistemaEmUso = Zend_Controller_Front::getInstance()->getRequest();
             $sCaminhoSistema = $sSistemaEmUso->getModuleName() . '/' . $sSistemaEmUso->getControllerName() . '/' . $sSistemaEmUso->getActionName();
         }
         $oDataProcessamento = new DateTime();
         $sLoginUsuario = Zend_Auth::getInstance()->getIdentity();
         $oUsuario = Administrativo_Model_Usuario::getByAttribute('login', $sLoginUsuario['login']);
         $sData = $oDataProcessamento->format('Y-m-d\\TH:i:s');
         $sCodigoProtocolo = SHA1(rand() . $sData . $aCodigoUsuario['id'] . time());
         $this->setProtocolo($sCodigoProtocolo);
         $this->setTipo($iTipo);
         $this->setMensagem(trim($sMensagem));
         $this->setSistema(trim($sCaminhoSistema));
         $this->setUsuario($oUsuario->getEntity());
         $this->setDataProcessamento($oDataProcessamento);
         $this->getEm()->persist($this->getEntity());
         $this->getEm()->flush();
     } catch (Exception $oErro) {
         throw new Exception($oErro->getMessage());
     }
     return $this->getEntity();
 }
开发者ID:arendasistemasintegrados,项目名称:mateusleme,代码行数:41,代码来源:Protocolo.php

示例9: registerAction

 public function registerAction()
 {
     $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
     $this->view->messages = $this->_flashMessenger->getMessages();
     $form = new Home_Form_Register();
     $this->view->registerForm = $form;
     //Verifica se existem dados de POST
     if ($this->getRequest()->isPost()) {
         $dataPost = $this->getRequest()->getPost();
         //Formulário corretamente preenchido?
         if ($form->isValid($dataPost)) {
             $login = $form->getValue('login');
             $name = $form->getValue('name');
             $pwd = $form->getValue('passkey');
             $data = array('login' => $login, 'name' => $name, 'password' => SHA1($pwd), 'created_at' => date('Y-m-d H:i:s'));
             $db = new Home_Model_DbTable_Users();
             $db->save($data);
             try {
                 Home_Model_Auth::login($login, $pwd);
                 //Redireciona para o Controller protegido
                 return $this->_helper->redirector->goToRoute(array('controller' => 'index', 'action' => 'index'), null, true);
             } catch (Exception $e) {
                 $this->view->message = $e->getMessage();
             }
         } else {
             //Formulário preenchido de forma incorreta
             $form->populate($dataPost);
             $this->view->messages = $form->getErrors();
         }
     }
 }
开发者ID:ezequielsp,项目名称:zf1,代码行数:31,代码来源:AuthController.php

示例10: checkMatch

 /**
  * Пользовательское правило валидации, проверяющее совпадает ли данное поле
  * с указанным
  * Enter description here ...
  * @param unknown_type $check
  * @param unknown_type $firstField
  * @param unknown_type $secondField
  * @return boolean
  */
 function checkMatch($check, $firstField, $secondField)
 {
     if (empty($this->data[$this->alias])) {
         return false;
     }
     $alias =& $this->data[$this->alias];
     return !empty($alias[$firstField]) && !empty($alias[$secondField]) && ($alias[$firstField] == $alias[$secondField] || $alias[$firstField] == SHA1(Configure::read('Security.salt') . $alias[$secondField]));
 }
开发者ID:ar7n,项目名称:mcl.resp.su,代码行数:17,代码来源:User.php

示例11: checkUser

 public function checkUser($email, $password)
 {
     $salt = $this->Users->findSalt($email);
     $id = $this->Users->find()->where(['email' => $email, 'password' => SHA1($password . $salt), 'activated' => true])->extract('id')->first();
     if ($id) {
         return $this->loginUser($id);
     }
     return false;
 }
开发者ID:Jurrieb,项目名称:lifespark,代码行数:9,代码来源:AuthenticationComponent.php

示例12: parseFileName

 private function parseFileName($url)
 {
     $this->urlHash = SHA1($url);
     $extension = $this->getExtension($url);
     $path = $this->getBaseDir() . DIRECTORY_SEPARATOR . $this->makeDeepPath($this->urlHash);
     $this->fileName = $path . DIRECTORY_SEPARATOR . $this->urlHash . self::SLUG_SEPARATOR . $extension;
     $this->makeTransformedFileName($path);
     $this->image->setFilename($this->getRealFilename());
 }
开发者ID:antonioribeiro,项目名称:lumen-image-processor,代码行数:9,代码来源:File.php

示例13: addUser

 /**
  * Resizes/resamples an image uploaded via a web form
  *
  * @param array $upload the array contained in $_FILES
  * @param bool $rename whether or not the image should be renamed
  * @return string the path to the resized uploaded file
  */
 public function addUser($u)
 {
     // Sanitize the data and store it in variables
     $username = htmlentities(strip_tags($u['username']), ENT_QUOTES);
     $password = htmlentities(strip_tags($u['password']), ENT_QUOTES);
     $sql = "INSERT INTO users (username, password, isAdmin)\n            VALUES (?, ?, ?)";
     $q = $this->db->prepare($sql);
     $q->execute(array($username, SHA1($password), $u['isAdmin']));
 }
开发者ID:Harrmalik,项目名称:get-lucid,代码行数:16,代码来源:users.inc.php

示例14: processLogin

 public function processLogin()
 {
     $username = isset($_POST["username"]) ? htmlentities($_POST["username"]) : null;
     $password = isset($_POST["password"]) ? htmlentities($_POST["password"]) : null;
     if (empty($username) || empty($password)) {
         throw new Exception("Either the username or password is empty");
     }
     return $this->_generateJWT($this->_getPermissionsOfUserWithEncryptedPassword($username, SHA1($password)));
 }
开发者ID:slh93,项目名称:CEEO,代码行数:9,代码来源:Login.php

示例15: verify

 /**
  * 验证签名
  * @param $prestr 需要签名的字符串
  * @param $sign 签名结果
  * @param $key 私钥
  * return 签名结果
  */
 static function verify($prestr, $sign, $key)
 {
     $prestr = $prestr . $key;
     $mysgin = SHA1($prestr);
     if ($mysgin == $sign) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:h3len,项目名称:Project,代码行数:17,代码来源:hg_sha1.class.php


注:本文中的SHA1函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。