• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP hash_password函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了hash_password函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
     }
 }
开发者ID:shannara,项目名称:banshee,代码行数:31,代码来源:profile.php


示例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;
 }
开发者ID:shannara,项目名称:banshee,代码行数:35,代码来源:profile.php


示例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);
         }
     }
 }
开发者ID:chiiiro,项目名称:SSP-TwitterApp,代码行数:33,代码来源:Settings.php


示例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);
 }
开发者ID:hellopsm,项目名称:robot,代码行数:31,代码来源:AuthTrait.php


示例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;
    }
}
开发者ID:CamTosh,项目名称:blogotext,代码行数:25,代码来源:util.php


示例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' => '[email protected]', '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' => '[email protected]', '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' => '[email protected]', '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' => '[email protected]', '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())));
 }
开发者ID:Klaudit,项目名称:aw-datacollection,代码行数:27,代码来源:SurveyApiTest.php


示例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');
 }
开发者ID:aldsdelram,项目名称:PUPNLPWebsite,代码行数:28,代码来源:Users.php


示例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)]);
     }
 }
开发者ID:hellopsm,项目名称:robot,代码行数:33,代码来源:2015_08_22_063319_agency.php


示例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 
         }
     }
 }
开发者ID:chiiiro,项目名称:SSP-TwitterApp,代码行数:32,代码来源:Index.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('[email protected]', $this->CI->users->user_data['email']);
     $this->assertEquals(hash_password('new_password', $this->CI->users->user_data['password']), $this->CI->users->user_data['password']);
 }
开发者ID:mefisto2009,项目名称:GameAP,代码行数:8,代码来源:users_test.php


示例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);
 }
开发者ID:zhaoshengloveqingqing,项目名称:usercenter,代码行数:8,代码来源:test_data.php


示例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;
 }
开发者ID:shannara,项目名称:banshee,代码行数:9,代码来源:password.php


示例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();
    }
}
开发者ID:pinoaffe,项目名称:content-management-thingy,代码行数:9,代码来源:forum-functions.php


示例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);
 }
开发者ID:newset,项目名称:robot,代码行数:10,代码来源:IEmployee.php


示例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;
    }
}
开发者ID:aldsdelram,项目名称:PUPNLPWebsite,代码行数:10,代码来源:security.php


示例16: u

 /**
  * 更新
  */
 public function u($rq = null)
 {
     $this->guarded = arr_except_vals($this->guarded, ['password']);
     if (!$rq) {
         $rq = rq();
     }
     if (isset($rq['password'])) {
         $rq['password'] = hash_password($rq['password']);
     }
     return parent::u($rq);
 }
开发者ID:hellopsm,项目名称:robot,代码行数:14,代码来源:IEmployee.php


示例17: 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->mongo_db->batchInsert('surveys', array(array('sid' => increment_counter('survey_sid'), 'title' => 'Meteor usage', 'status' => 1, 'introduction' => 'The text the user has to read.', 'files' => array('xls' => NULL, 'xml' => "valid_survey.xml", 'last_conversion' => array('date' => Mongo_db::date(), 'warnings' => NULL)), 'agents' => array(3), 'created' => Mongo_db::date())));
     self::$CI->mongo_db->batchInsert('users', array(array('uid' => increment_counter('user_uid'), 'email' => '[email protected]', '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())));
 }
开发者ID:Klaudit,项目名称:aw-datacollection,代码行数:12,代码来源:SurveyRespondentsImportTest.php


示例18: action

 /**
  * Function is used for registering new users.
  * It checks entered data, register new user and redirects to user's twitter wall.
  * User must enter security number to prevent robot attacks.
  */
 public function action()
 {
     $main = new Main();
     $main->setPageTitle("Sign up for TwitterApp");
     $register = new \templates\Register();
     $main->setBody($register);
     echo $main;
     if (post('register')) {
         $firstName = htmlentities(trim(post('fname')));
         $lastName = htmlentities(trim(post('lname')));
         $username = htmlentities(trim(post('username')));
         $password = trim(post('password'));
         $hashedPassword = hash_password($password);
         $confirmedPassword = trim(post('cpassword'));
         $email = trim(post('email'));
         $userSecurityNumber = (int) trim(post('security'));
         //server-side validation
         $error = false;
         if (!ctype_alpha($firstName) || strlen($firstName) < 3 || strlen($firstName) > 25) {
             $error = true;
         }
         if (!ctype_alpha($lastName) || strlen($lastName) < 3 || strlen($lastName) > 25) {
             $error = true;
         }
         if (!ctype_alnum($username) || strlen($username) < 4 || strlen($lastName) > 25) {
             $error = true;
         }
         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) {
             $user = new User();
             $user->setFirstName($firstName);
             $user->setLastName($lastName);
             $user->setUsername($username);
             $user->setPassword($hashedPassword);
             $user->setEmail($email);
             try {
                 UserRepository::registerUser($user);
             } catch (\PDOException $e) {
                 $e->getMessage();
             }
         }
     }
 }
开发者ID:chiiiro,项目名称:SSP-TwitterApp,代码行数:56,代码来源:Register.php


示例19: add_user

function add_user($username, $password, $email, $studentid)
{
    $userid = get_user_number() + 1;
    //得到用户的数量并+1生成新用户的ID
    $password = hash_password($password);
    //加密密码
    $query = "INSERT INTO user(userid, username, password, email, studentid) VALUE('{$userid}', '{$username}', '{$password}','{$email}','{$studentid}')";
    if ($result = mysql_query($query)) {
        mysql_query("UPDATE status SET status.value = status.value+1 WHERE status.name = 'usernumber'");
        return true;
    } else {
        die("Error in query: {$query}. " . mysql_error());
    }
}
开发者ID:banixc,项目名称:TVker,代码行数:14,代码来源:functions.php


示例20: authenticate

 /**
  * Try to authenticate someone.
  * @param string $username - Their username.
  * @param srring $password - Their (unhashed) password.
  * @return boolean
  */
 public function authenticate($username, $password)
 {
     $password = hash_password($username, $password);
     if ($this->model('user')->reset()->where('username', $username)->where('password', $password)->count() == 0) {
         return false;
     }
     $user = $this->model('user')->first();
     $key = random_string(32);
     $id = $this->model('session')->insert(['user_id' => $user->id, 'key' => $key, 'ip' => ip2long($_SERVER['REMOTE_ADDR'])]);
     setcookie('pws_id', $id, time() + 3600 * 24 * 365.25 * 10, '/');
     setcookie('pws_uid', $user->id, time() + 3600 * 24 * 365.25 * 10, '/');
     setcookie('pws_key', $key, time() + 3600 * 24 * 365.25 * 10, '/');
     return true;
 }
开发者ID:WoutervdBrink,项目名称:PWS-Community,代码行数:20,代码来源:AuthenticationService.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP hash_pbkdf2函数代码示例发布时间:2022-05-15
下一篇:
PHP hash_pad函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap