本文整理汇总了PHP中hashPassword函数的典型用法代码示例。如果您正苦于以下问题:PHP hashPassword函数的具体用法?PHP hashPassword怎么用?PHP hashPassword使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hashPassword函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dummyUser
function dummyUser($db)
{
$pass = hashPassword("admin");
$key = generateRandomString();
$sql = "INSERT INTO users VALUES (NULL,'admin','{$pass}','{$key}',NULL);";
execSql($db, $sql, "add admin user");
}
示例2: login
function login($email, $password)
{
$mysqli = new Connection();
$db = $mysqli->connect();
//hash the password
$password = hashPassword($password);
//prepare the query
$query = $db->prepare("SELECT id FROM users WHERE email = ? AND password = ? LIMIT 1") or die("error");
$query->bind_param('ss', $email, $password);
//excuting
$query->execute();
//store results
$query->store_result();
//bind results
$query->bind_result($id);
$query->fetch();
//get the num rows
if ($query->num_rows == 1) {
$user_browser = $_SERVER['HTTP_USER_AGENT'];
session_start();
$_SESSION['login_string'] = array();
$_SESSION['login_string']['browserInfo'] = hash('sha512', $user_browser);
$_SESSION['login_string']['id'] = hash('sha512', $id);
return TRUE;
} else {
return FALSE;
}
//close the query
$db->close();
}
示例3: insertUser
function insertUser($user, $conn)
{
$salt = createSalt();
$password = hashPassword($user['password'], $salt);
$sql = "INSERT INTO users(username, salt, password, f_name, l_name, email, group, permissions) \n\t\t\tVALUES(:username, :salt, :password, :f_name, :l_name, :email, :group, :permissions)";
$psql = $conn->prepare($sql);
$psql->execute(array(":username" => $user['username'], ":salt" => $salt, ":password" => $password, ":f_name" => $user['f_name'], ":l_name" => $user['l_name'], ":email" => $user['email'], ":group" => $user['group'], ":permissions" => $user['permissions']));
}
示例4: testPassword
function testPassword($password, $db_password)
{
$hashedPassword = hashPassword($password);
if (strcmp($hashedPassword, $db_password) == 0) {
return true;
} else {
return false;
}
}
示例5: password_save
/**
* LDAP Password Driver
*
* Driver for passwords stored in LDAP
* This driver use the PEAR Net_LDAP2 class (http://pear.php.net/package/Net_LDAP2).
*
* @version 1.0 (2009-06-24)
* @author Edouard MOREAU <edouard.moreau@ensma.fr>
*
* function hashPassword based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
* function randomSalt based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
*
*/
function password_save($curpass, $passwd)
{
$rcmail = rcmail::get_instance();
require_once 'Net/LDAP2.php';
// Building user DN
$userDN = str_replace('%login', $_SESSION['username'], $rcmail->config->get('password_ldap_userDN_mask'));
$parts = explode('@', $_SESSION['username']);
if (count($parts) == 2) {
$userDN = str_replace('%name', $parts[0], $userDN);
$userDN = str_replace('%domain', $parts[1], $userDN);
}
if (empty($userDN)) {
return PASSWORD_CONNECT_ERROR;
}
// Connection Method
switch ($rcmail->config->get('password_ldap_method')) {
case 'user':
$binddn = $userDN;
$bindpw = $curpass;
break;
case 'admin':
$binddn = $rcmail->config->get('password_ldap_adminDN');
$bindpw = $rcmail->config->get('password_ldap_adminPW');
break;
default:
$binddn = $userDN;
$bindpw = $curpass;
break;
// default is user mode
}
// Configuration array
$ldapConfig = array('binddn' => $binddn, 'bindpw' => $bindpw, 'basedn' => $rcmail->config->get('password_ldap_basedn'), 'host' => $rcmail->config->get('password_ldap_host'), 'port' => $rcmail->config->get('password_ldap_port'), 'starttls' => $rcmail->config->get('password_ldap_starttls'), 'version' => $rcmail->config->get('password_ldap_version'));
// Connecting using the configuration array
$ldap = Net_LDAP2::connect($ldapConfig);
// Checking for connection error
if (PEAR::isError($ldap)) {
return PASSWORD_CONNECT_ERROR;
}
// Crypting new password
$newCryptedPassword = hashPassword($passwd, $rcmail->config->get('password_ldap_encodage'));
if (!$newCryptedPassword) {
return PASSWORD_CRYPT_ERROR;
}
// Writing new crypted password to LDAP
$userEntry = $ldap->getEntry($userDN);
if (Net_LDAP2::isError($userEntry)) {
return PASSWORD_CONNECT_ERROR;
}
if (!$userEntry->replace(array($rcmail->config->get('password_ldap_pwattr') => $newCryptedPassword), $rcmail->config->get('password_ldap_force_replace'))) {
return PASSWORD_CONNECT_ERROR;
}
if (Net_LDAP2::isError($userEntry->update())) {
return PASSWORD_CONNECT_ERROR;
}
// All done, no error
return PASSWORD_SUCCESS;
}
示例6: password_save
/**
* LDAP Password Driver
*
* Driver for passwords stored in LDAP
* This driver use the PEAR Net_LDAP2 class (http://pear.php.net/package/Net_LDAP2).
*
* @version 1.1 (2010-04-07)
* @author Edouard MOREAU <edouard.moreau@ensma.fr>
*
* function hashPassword based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
* function randomSalt based on code from the phpLDAPadmin development team (http://phpldapadmin.sourceforge.net/).
*
*/
function password_save($curpass, $passwd)
{
$rcmail = rcmail::get_instance();
require_once 'Net/LDAP2.php';
// Building user DN
if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) {
$userDN = substitute_vars($userDN);
} else {
$userDN = search_userdn($rcmail);
}
if (empty($userDN)) {
return PASSWORD_CONNECT_ERROR;
}
// Connection Method
switch ($rcmail->config->get('password_ldap_method')) {
case 'admin':
$binddn = $rcmail->config->get('password_ldap_adminDN');
$bindpw = $rcmail->config->get('password_ldap_adminPW');
break;
case 'user':
default:
$binddn = $userDN;
$bindpw = $curpass;
break;
}
// Configuration array
$ldapConfig = array('binddn' => $binddn, 'bindpw' => $bindpw, 'basedn' => $rcmail->config->get('password_ldap_basedn'), 'host' => $rcmail->config->get('password_ldap_host'), 'port' => $rcmail->config->get('password_ldap_port'), 'starttls' => $rcmail->config->get('password_ldap_starttls'), 'version' => $rcmail->config->get('password_ldap_version'));
// Connecting using the configuration array
$ldap = Net_LDAP2::connect($ldapConfig);
// Checking for connection error
if (PEAR::isError($ldap)) {
return PASSWORD_CONNECT_ERROR;
}
// Crypting new password
$newCryptedPassword = hashPassword($passwd, $rcmail->config->get('password_ldap_encodage'));
if (!$newCryptedPassword) {
return PASSWORD_CRYPT_ERROR;
}
// Writing new crypted password to LDAP
$userEntry = $ldap->getEntry($userDN);
if (Net_LDAP2::isError($userEntry)) {
return PASSWORD_CONNECT_ERROR;
}
$pwattr = $rcmail->config->get('password_ldap_pwattr');
$force = $rcmail->config->get('password_ldap_force_replace');
if (!$userEntry->replace(array($pwattr => $newCryptedPassword), $force)) {
return PASSWORD_CONNECT_ERROR;
}
if (Net_LDAP2::isError($userEntry->update())) {
return PASSWORD_CONNECT_ERROR;
}
// All done, no error
return PASSWORD_SUCCESS;
}
示例7: checkUserPassword
function checkUserPassword($username, $givenPassword)
{
$rep = false;
if (isset($username) && isset($givenPassword)) {
if (checkUserExists($username)) {
if (getPassword($username) == hashPassword($username, $givenPassword)) {
$rep = true;
}
}
}
return $rep;
}
示例8: changePassword
function changePassword($email, $pass)
{
$hash = hashPassword($pass);
$con = connectDatabase();
while (1) {
$stmt = $con->prepare("CALL changePassword(?,?)");
$stmt->bind_param("ss", $email, $hash);
$stmt->execute();
$stmt->close();
break;
}
$con->close();
}
示例9: validateUser
function validateUser($pUsername, $pPassword)
{
// See if the username and password are valid.
$sql = "SELECT username FROM user_data\n\t\tWHERE username = '" . mysql_real_escape_string($pUsername) . "' AND password = '" . hashPassword($pPassword, SALT1, SALT2) . "' LIMIT 1";
$query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error());
// If one row was returned, the user was logged in!
if (mysql_num_rows($query) == 1) {
$row = mysql_fetch_assoc($query);
$_SESSION['username'] = $row['username'];
$_SESSION['loggedin'] = true;
return true;
}
return false;
}
示例10: submitPassword
function submitPassword($username, $newPassword)
{
try {
$connection = new PDO("mysql:host=" . DB_HOST_NAME . ";dbname=" . DB_NAME . ";charset=utf8", DB_USER_NAME, DB_PASSWORD);
// Exceptions fire when occur
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$accountInformationUpdate = $connection->prepare('UPDATE ' . ADMIN_CREDENTIAL_TABLE . ' SET PASSWORD = :newPassword WHERE EMAIL = :username');
$accountInformationUpdate->execute(array(':newPassword' => hashPassword($newPassword), ':username' => $username));
} catch (PDOException $e) {
echo "\r\n <div>\r\n Error: " . $e->getMessage() . "</div>";
return FALSE;
}
return TRUE;
}
示例11: logUserIn
function logUserIn($name, $password, $keepLog = false)
{
$name = secureString($name);
$password = hashPassword(secureString($password), getUserData(array('name' => $name))['salt']);
$userData = getUserData(array('name' => $name, 'password' => $password));
if ($userData) {
setSessionVar('login', true);
setSessionVar('userID', $userData['id']);
if ($keepLog) {
setSessionVar('saveKeepLog', true);
}
return true;
} else {
return false;
}
}
示例12: addInformation
function addInformation($mysql_host, $mysql_username, $mysql_password, $mysql_database, $account_email, $account_pass)
{
$conn = mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
mysql_select_db($mysql_database, $conn);
$sql = "INSERT INTO lb_sys_accounts(account_email,account_password,account_created_date,account_status) VALUES ('" . $account_email . "','" . hashPassword($account_pass) . "','" . Date("Y-m-d H:i:s") . "',1)";
if (mysql_query($sql)) {
$sql = "Select * from lb_sys_accounts";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$id = $row['account_id'];
$sql = "INSERT INTO lb_sys_account_profiles(account_id,account_profile_given_name) VALUES (" . $id . ",'Admin')";
mysql_query($sql);
// add subcription
$sql1 = "INSERT INTO lb_sys_account_subscriptions(account_id,account_subscription_package_id,account_subscription_start_date,account_subscription_status_id,subscription_name) VALUES (" . $id . ",0,'" . Date("Y-m-d H:i:s") . "',1,'My Company')";
mysql_query($sql1);
}
}
示例13: add
public function add()
{
if ($_POST) {
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|max_length[12]');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|max_length[24]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[8]|matches[confirm_password]');
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required');
$this->form_validation->set_rules('phone', 'Phone', 'required');
$this->form_validation->set_rules('mobile', 'Mobile', 'required');
$this->form_validation->set_rules('company', 'Company', 'required');
$this->form_validation->set_rules('position', 'Position', 'required');
$this->form_validation->set_message('is_unique', 'The %s is already exist');
if ($this->_data['type'] == 'superadmin') {
$this->form_validation->set_rules('type', 'Type', 'required');
}
if ($this->form_validation->run()) {
$info['first_name'] = $_POST['first_name'];
$info['last_name'] = $_POST['last_name'];
$info['email'] = $_POST['email'];
$info['salt'] = $salt = salt();
$info['password'] = hashPassword($_POST['password'], $salt);
$info['phone'] = $_POST['phone'];
$info['mobile'] = $_POST['mobile'];
$info['company'] = $_POST['company'];
$info['position'] = $_POST['position'];
if ($this->_data['type'] == 'superadmin') {
$info['type'] = $_POST['type'];
} else {
$info['type'] = 'user';
}
$new_user_id = $this->user_model->newUser($info);
$details['user_id'] = $new_user_id;
$details['field'] = 'creator_id';
$details['value'] = $this->session->userdata('user_id');
$this->db->insert('user_details', $details);
//$this->_send_email($info);
redirect('user/user');
}
}
$this->_data['breadcrumb'] = 'user/add_user';
$this->_data['page_title'] = "Create User";
$this->_data['companyList'] = $this->user_model->companyList();
$this->_data['view'] = 'user_add';
$this->load->view('user/home', $this->_data);
}
示例14: chk_user
public function chk_user()
{
$val = $this->db->get_where('users', array('email' => $_POST['username']))->row();
$salt = $val->salt;
$pass = hashPassword($_POST['password'], $salt);
$user = $this->db->get_where('users', array('email' => $_POST['username'], 'password' => $pass));
if ($user->num_rows() > 0) {
$user = $user->row_array();
$type = $user['type'];
if ($user['status'] != 'Y') {
$this->form_validation->set_message('chk_user', 'Your account is not active');
return false;
}
return true;
} else {
$this->form_validation->set_message('chk_user', "Invalid Email or Password");
return false;
}
}
示例15: login
public function login($username, $password, $remember_me, $CONF)
{
$result = $this->db->select("users", "username=? AND password=?", array($username, $password));
if ($result) {
$user = new User($result, $this->db);
$_SESSION[$CONF['session_prefix'] . "user"] = serialize($user);
$_SESSION[$CONF['session_prefix'] . "logged_in"] = 1;
if ($remember_me) {
$identifier = hashPassword($username, $this->conf);
$token = bin2hex(openssl_random_pseudo_bytes(20));
$data = array("user_id" => $user->id, "identifier" => $identifier, "token" => $token, "timeout" => date("Y-m-d H:i:s", time() + 60 * 60 * 24 * 7));
$this->db->insert($data, "sessions");
setcookie($CONF['session_prefix'] . 'auth', "{$identifier}:{$token}", time() + 60 * 60 * 24 * 7, '/', '.' . $this->conf['host']);
}
return true;
} else {
return false;
}
}