本文整理汇总了PHP中hash_password函数的典型用法代码示例。如果您正苦于以下问题:PHP hash_password函数的具体用法?PHP hash_password怎么用?PHP hash_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hash_password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
if ($this->user->logged_in == false) {
$this->output->add_tag("result", "You are not logged in!", array("url" => ""));
return;
}
$this->output->description = "Profile";
$this->output->keywords = "profile";
$this->output->title = "Profile";
if ($this->user->status == USER_STATUS_CHANGEPWD) {
$this->output->add_message("Please, change your password.");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
/* Update profile
*/
$_POST["hashed"] = hash_password($_POST["password"], $this->user->username);
if ($this->model->profile_oke($_POST) == false) {
$this->show_profile_form($_POST);
} else {
if ($this->model->update_profile($_POST) === false) {
$this->output->add_tag("result", "Error while updating profile.", array("url" => "profile"));
} else {
$this->output->add_tag("result", "Profile has been updated.", array("url" => $this->settings->start_page));
$this->user->log_action("profile updated");
}
}
} else {
$user = array("fullname" => $this->user->fullname, "email" => $this->user->email);
$this->show_profile_form($user);
}
}
示例2: profile_oke
public function profile_oke($profile)
{
$result = true;
if (trim($profile["fullname"]) == "") {
$this->output->add_message("Fill in your name.");
$result = false;
}
if (valid_email($profile["email"]) == false) {
$this->output->add_message("Invalid e-mail address.");
$result = false;
} else {
if (($check = $this->db->entry("users", $profile["email"], "email")) != false) {
if ($check["id"] != $this->user->id) {
$this->output->add_message("E-mail address already exists.");
$result = false;
}
}
}
if (hash_password($profile["current"], $this->user->username) != $this->user->password) {
$this->output->add_message("Current password is incorrect.");
$result = false;
}
if ($profile["password"] != "") {
if ($profile["password"] != $profile["repeat"]) {
$this->output->add_message("New passwords do not match.");
$result = false;
} else {
if ($this->user->password == $profile["hashed"]) {
$this->output->add_message("New password must be different from current password.");
$result = false;
}
}
}
return $result;
}
示例3: changePassword
/**
* Changes user's password after validation of entered data.
* User must enter security number to prevent robot attacks.
*/
public function changePassword()
{
checkUnauthorizedAccess();
$main = new Main();
$main->setPageTitle("Password settings");
$changePassword = new ChangePassword();
$main->setBody($changePassword);
echo $main;
$username = getUsername();
if (post('change-pwd')) {
$password = post('first');
$confirmedPassword = post('second');
$userSecurityNumber = post('security');
$error = false;
if (!ctype_alnum($password) || strlen($password) < 4 || strlen($password) > 25) {
$error = true;
}
if (!ctype_alnum($confirmedPassword) || strlen($confirmedPassword) < 4 || strlen($confirmedPassword) > 25) {
$error = true;
}
if ($userSecurityNumber < 1113 || $userSecurityNumber > 1207) {
$error = true;
}
if ($password === $confirmedPassword && !$error) {
$hashedPassword = hash_password($password);
UserRepository::changePassword($username, $hashedPassword);
}
}
}
示例4: login
/**
* 登入方法
* @param null $input
* @return array
*/
public function login($input = null)
{
$input = $input ? $input : rq();
if (!empty($input['user_type']) && $input['user_type'] == 'doctor' && !empty($input['cust_id'])) {
$d = M('doctor');
$d = $d->where('cust_id', $input['cust_id'])->first();
if ($d) {
log_him_in(['uid' => $d->id]);
add_chara($input['user_type']);
return ss();
}
return $d ? ss($d) : ee(2);
}
if (!empty($input['user_type']) && !empty($input['username']) && !empty($input['password'])) {
$input['password'] = hash_password($input['password']);
$user = $this->user_exists($input['user_type'], array_only($input, ['username', 'password']));
if ($user) {
log_him_in(['username' => $user->username, 'uid' => $user->id]);
add_chara($input['user_type']);
return ss();
}
} else {
return ee(2);
}
return ee(2);
}
示例5: check_session
function check_session()
{
if ($GLOBALS['use_ip_in_session'] == 1) {
$ip = get_real_ip();
} else {
$ip = date('m');
}
@session_start();
ini_set('session.cookie_httponly', TRUE);
// use a cookie to remain logged in
$user_id = hash_password($GLOBALS['mdp'] . $GLOBALS['identifiant'] . $GLOBALS['salt'], md5($_SERVER['HTTP_USER_AGENT'] . $ip . $GLOBALS['salt']));
if (isset($_COOKIE['BT-admin-stay-logged']) and $_COOKIE['BT-admin-stay-logged'] == $user_id) {
$_SESSION['user_id'] = md5($user_id);
session_set_cookie_params(365 * 24 * 60 * 60);
// set new expiration time to the browser
session_regenerate_id(true);
// Send cookie
return TRUE;
}
if (!isset($_SESSION['user_id']) or $_SESSION['user_id'] != $GLOBALS['identifiant'] . $GLOBALS['mdp'] . md5($_SERVER['HTTP_USER_AGENT'] . $ip)) {
return FALSE;
} else {
return TRUE;
}
}
示例6: setUpBeforeClass
public static function setUpBeforeClass()
{
self::$CI =& get_instance();
// Clean db!
self::$CI->mongo_db->dropDb('aw_datacollection_test');
// Change Controller.
self::$CI = new Survey();
self::$CI->mongo_db->switchDb('mongodb://localhost:27017/aw_datacollection_test');
self::$CI->config->set_item('aw_survey_files_location', ROOT_PATH . 'tests/test_resources/surveys/');
self::$CI->load->helper('password_hashing');
// Original status restriction.
self::$CI->config->load('status_restrictions');
self::$status_resctriction_config = self::$CI->config->item('status_restrictions');
// Create temp directory.
$path = ROOT_PATH . 'tests/tmp/survey_results/';
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
self::$CI->config->set_item('aw_survey_results_location', $path);
// Index.
self::$CI->mongo_db->addIndex('call_tasks', array('ctid' => 'asc'));
// Instead of creating all the content before starting the tests
// we only create users since those will not be updated.
// Every other content will be created when needed.
// This allows more control over what's happening.
self::$CI->mongo_db->batchInsert('users', array(array('uid' => 9901, 'email' => 'admin@localhost.dev', 'name' => 'Admin', 'username' => 'admin', 'password' => hash_password('admin'), 'roles' => array(ROLE_ADMINISTRATOR), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => 9902, 'email' => 'regular@localhost.dev', 'name' => 'Regular user', 'username' => 'regular', 'password' => hash_password('regular'), 'roles' => array(), 'author' => 1, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => 9903, 'email' => 'agent@localhost.dev', 'name' => 'The Agent', 'username' => 'agent', 'password' => hash_password('agent'), 'roles' => array(ROLE_CC_AGENT), 'author' => 1, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => 9904, 'email' => 'blocked_agent@localhost.dev', 'name' => 'The Blocked Agent', 'username' => 'bloked_agent', 'password' => hash_password('blocked_agent'), 'roles' => array(ROLE_CC_AGENT), 'author' => 1, 'status' => User_entity::STATUS_BLOCKED, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date())));
}
示例7: register
public function register()
{
check_if_already_logged_in();
$data["page"] = "register";
if (isset($_POST['btnRegister'])) {
$input = array("username" => $_POST['username'], "password" => $_POST['password'], "confirmpass" => $_POST['password_confirm'], "firstname" => $_POST['firstname'], "middlename" => $_POST['middlename'], "lastname" => $_POST['lastname'], "email" => $_POST['email'], "gender" => isset($_POST['gender']) ? $_POST['gender'] : "", "occupation" => $_POST['occupation'], "otherinfo" => $_POST['otherinfo']);
$data["error"] = verify_data($input);
if ($data["error"]["count"] == 0) {
$salt = generate_salt();
$userdata["username"] = $input["username"];
$userdata["salt"] = encrypt_salt($salt, 'enElpiPUP1516');
$userdata["password"] = hash_password($input["password"], $salt);
$userdata["type"] = "member";
$other["first_name"] = $input["firstname"];
$other["middle_name"] = $input["middlename"];
$other["last_name"] = $input["lastname"];
$other["email"] = $input["email"];
$other["gender"] = $input["gender"];
$other["occupation"] = $input["occupation"];
$other["about"] = $input["otherinfo"];
$user = $this->Users_model->insert($userdata, $other);
header('Location: register');
}
}
$this->load->view('templates/header');
$this->load->view('users/register', $data);
$this->load->view('templates/footer');
}
示例8: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('i_' . $this->ins_name, function (Blueprint $t) {
$t->engine = 'InnoDB';
$t->increments('id');
$t->text('name');
$t->text('name_in_charge');
$t->integer('city_id')->unsigned();
$t->integer('province_id')->unsigned();
$t->text('location_detail');
$t->string('username')->unique();
$t->string('password');
$t->string('phone')->nullable();
$t->string('email')->nullable();
$t->date('started_at')->nullable();
$t->date('ended_at')->nullable();
$t->smallInteger('status')->default(1);
// 0为冻结账户
$t->text('memo')->nullable();
$t->softDeletes();
$t->timestamps();
});
$count = 1000;
db_c($this->ins_name, 'i', ['id' => 1, 'name' => '自营', 'name_in_charge' => str_random(2) . ' ' . str_random(2), 'location_detail' => str_random(100), 'started_at' => date("Y-m-d H:i:s", 1440560208), 'ended_at' => date("Y-m-d H:i:s", 1840560208), 'city_id' => rand(36, 398), 'province_id' => rand(2, 35), 'username' => $this->ins_name . 'self', 'password' => hash_password($this->ins_name . 'self'), 'phone' => rand(13000000000.0, 13999999999.0), 'email' => str_random(3) . '@' . str_random(3) . '.com', 'memo' => str_random(200), 'status' => rand(0, 1)]);
for ($i = 0; $i < $count; $i++) {
db_c($this->ins_name, 'i', ['name' => str_random(2) . '集团', 'name_in_charge' => str_random(2) . ' ' . str_random(2), 'location_detail' => str_random(100), 'started_at' => date("Y-m-d H:i:s", mt_rand(1161302400, 1440560208)), 'ended_at' => date("Y-m-d H:i:s", mt_rand(1161302400, 1440560208) + rand(1000000, 999999999)), 'city_id' => rand(36, 398), 'province_id' => rand(2, 35), 'username' => $this->ins_name . $i, 'password' => hash_password($this->ins_name . $i), 'phone' => rand(13000000000.0, 13999999999.0), 'email' => str_random(3) . '@' . str_random(3) . '.com', 'memo' => str_random(200), 'status' => rand(0, 1)]);
}
}
示例9: action
/**
* Function renders main page and implements user login behaviour.
* If user is already logged in, he will be redirected to his twitter wall.
* If user doesn't exist or entered data is wrong, warning message will show.
*/
public function action()
{
if (isLoggedIn()) {
redirect(\route\Route::get("twitterWall")->generate(array("id" => UserRepository::getIdByUsername($_SESSION['username']))));
}
$main = new Main();
$main->setPageTitle("Twitter App");
$body = new \templates\Index();
$main->setBody($body);
echo $main;
if (UserRepository::isLoggedIn()) {
redirect(\route\Route::get("twitterWall")->generate());
}
if (post('login')) {
$username = htmlentities(trim(post('username')));
$password = htmlentities(trim(post('password')));
$hashedPassword = hash_password($password);
if (UserRepository::login($username, $hashedPassword)) {
redirect(\route\Route::get("twitterWall")->generate(array("id" => UserRepository::getIdByUsername($_SESSION['username']))));
exit;
} else {
?>
<script src="assets/js/loginError.js"></script>
<?php
}
}
}
示例10: test_get_user_data
public function test_get_user_data()
{
$this->CI->users->get_user_data(1);
$this->assertEquals('test', $this->CI->users->user_data['login']);
$this->assertEquals('username', $this->CI->users->user_data['name']);
$this->assertEquals('nikita.hldm@gmail.com', $this->CI->users->user_data['email']);
$this->assertEquals(hash_password('new_password', $this->CI->users->user_data['password']), $this->CI->users->user_data['password']);
}
示例11: addUserBasicInfo
public function addUserBasicInfo()
{
if (!$this->the_user_id) {
$this->addUser();
}
$this->the_user_basic_info_id = $this->user_basic_info_model->insert(array('id' => 1000, 'uid' => $this->the_user_id, 'username' => 'jack', 'password' => hash_password('jack'), 'mobile' => '123456'));
$this->the_user_basic_info = $this->user_basic_info_model->load($this->the_user_basic_info_id);
}
示例12: save_password
public function save_password($username, $password)
{
if ($username == "") {
return false;
}
$password["password"] = hash_password($password["password"], $username);
$query = "update users set password=%s where username=%s";
return $this->db->query($query, $password["password"], $username) != false;
}
示例13: change_password
function change_password($users, $passwords, $user, $old, $new)
{
if (verify_password($users, $passwords, $user, $old)) {
$new_salt = generate_random_string(20);
$passwords[array_keys($users, $user)][0] = hash_password($new, $new_salt);
$passwords[array_keys($users, $user)][1] = $new_salt;
logout();
}
}
示例14: change_password
public function change_password($row = null)
{
$row = $row ? $row : rq();
$ins = $this->find($row['id']);
$ins->password = hash_password($row['password']);
$r = $ins->save();
// trigger log
$this->eventFire('pass', $ins);
return $r ? ss($r) : ee(1);
}
示例15: verify
function verify($password, $hashed_password, $salt)
{
$original_salt = decrypt_salt($salt, 'enElpiPUP1516');
$hashed_password2 = hash_password($password, $original_salt);
if ($hashed_password2 === $hashed_password) {
return true;
} else {
return false;
}
}