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


PHP password_hash函数代码示例

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


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

示例1: add_member

function add_member($username, $password)
{
    require 'password.php';
    try {
        define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));
        define('DB_PORT', getenv('OPENSHIFT_MYSQL_DB_PORT'));
        define('DB_USER', getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
        define('DB_PASS', getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));
        define('DB_NAME', getenv('OPENSHIFT_GEAR_NAME'));
        try {
            $dsn = 'mysql:dbname=members;host=' . DB_HOST . ';port=' . DB_PORT;
            $db = new PDO($dsn, DB_USER, DB_PASS);
        } catch (PDOException $ex) {
            echo 'Error!: ' . $ex->getMessage();
            die;
        }
        $password = password_hash($password, PASSWORD_BCRYPT);
        echo $password;
        $query = $db->query("USE members");
        $query = $db->query("INSERT INTO members (username, password) VALUES ('{$username}', '{$password}')");
        header('Location: main_login.php');
        return TRUE;
    } catch (Exception $ex) {
        return FALSE;
    }
}
开发者ID:jcomish,项目名称:Web2,代码行数:26,代码来源:model.php

示例2: CreateNewAccount

 public static function CreateNewAccount()
 {
     // validate input
     if (!self::validateUserName(Request::post('new_account_name'))) {
         return false;
     }
     if (!self::validateUserPassword(Request::post('new_account_password'), Request::post('new_account_password_repeat'))) {
         return false;
     }
     // connect to database
     $db = Database::getFactory()->getConnection();
     if (!$db) {
         Session::add('feedback_negative', 'Critical error. Can\'t connect to database.');
         return false;
     }
     // get a password hash
     $passwordHash = password_hash(Request::post('new_account_password'), PASSWORD_DEFAULT);
     // write new users data into database
     $sql = "INSERT INTO users ( user_id,  user_name,  user_password,  user_registration_time)\n                       VALUES (:user_id, :user_name, :user_password, :user_registration_time)";
     $query = $db->prepare($sql);
     $query->execute(array(':user_id' => null, ':user_name' => Request::post('new_account_name'), ':user_password' => $passwordHash, ':user_registration_time' => time('c')));
     $count = $query->rowCount();
     if ($count == 1) {
         Session::add('feedback_positive', 'New account created successfully.');
         return true;
     }
     // if it gets to this point, something went wrong
     Session::add('feedback_negative', 'Something went wrong.');
     return false;
 }
开发者ID:shx13,项目名称:skeletor,代码行数:30,代码来源:RegistrationModel.php

示例3: logreg

 public function logreg()
 {
     $flag = 1;
     $this->load->library('form_validation');
     // установка правил валидации
     $this->form_validation->set_rules($this->config->item('reg_validation'));
     if ($this->form_validation->run() === TRUE) {
         // получение данных с формы
         $email = $this->input->post('email');
         $pass = $this->input->post('password');
         $name = $this->input->post('name');
         $lastname = $this->input->post('lastname');
         $birthday = $this->input->post('birthday');
         $this->load->model("User_Model");
         $this->load->model('Cart_Model');
         $data['result'] = $this->User_Model->check_user($email, $pass);
         if ($data['result']['status'] == 2 && $flag > 0) {
             $this->User_Model->insert(array('email' => $email, 'password' => password_hash($pass, PASSWORD_DEFAULT), 'name' => $name, 'lastname' => $lastname, 'birthday' => $birthday));
             $data['result'] = array('status' => 0);
         }
     } else {
         $data['result']['status'] = 1;
         $data['result']['message'] = $this->form_validation->error_string();
     }
     $this->output->json_output($data);
 }
开发者ID:paintcast,项目名称:loftphpdz7,代码行数:26,代码来源:User.php

示例4: testPassword

 public function testPassword()
 {
     $passwd = password_hash('WowSoSecretPassword', PASSWORD_DEFAULT);
     $this->assertEmpty($this->user->getPassword());
     $this->user->setPassword($passwd);
     $this->assertEquals($passwd, $this->user->getPassword());
 }
开发者ID:fer2d2,项目名称:fernando.moro.php.ecp1,代码行数:7,代码来源:UserTest.php

示例5: add

 public function add()
 {
     $this->userObject = new User();
     $data = array('email' => $_POST['email'], 'password' => password_hash($_POST['password'], PASSWORD_DEFAULT), 'first_name' => $_POST['firstname'], 'last_name' => $_POST['lastname']);
     $result = $this->userObject->add_user($data);
     $this->set('message', $result);
 }
开发者ID:klgrimley,项目名称:CIT-313,代码行数:7,代码来源:registercontroller.php

示例6: changePasswordddd

 public function changePasswordddd()
 {
     $pass = password_hash('Opti369', PASSWORD_DEFAULT);
     $data = array('password' => $pass);
     $this->db->where('id', 13);
     $this->db->update('tbl_sites', $data);
 }
开发者ID:svenhabex,项目名称:dashboard-hotspot,代码行数:7,代码来源:Site_model.php

示例7: postShowRegisterPage

 public function postShowRegisterPage()
 {
     $errors = [];
     $validation_data = ['first_name' => 'min:3', 'last_name' => 'min:3', 'email' => 'email', 'verify_email' => 'email', 'password' => 'min:3', 'email' => 'equalTo:verify_email', 'password' => 'equalTo:verify_password'];
     // validate data
     $validator = new Validator();
     $errors = $validator->isValid($validation_data);
     //  print_r($errors);
     //  exit();
     // if validation fails, go back to register
     // page and display error message
     if (sizeof($errors) > 0) {
         $_SESSION['msg'] = $errors;
         header("Location: /register");
         exit;
     }
     // save this data into a database
     $user = new User();
     $user->first_name = $_REQUEST['first_name'];
     $user->last_name = $_REQUEST['last_name'];
     $user->email = $_REQUEST['email'];
     $user->password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT);
     $user->save();
     echo "Posted!";
 }
开发者ID:Andy16296,项目名称:acme,代码行数:25,代码来源:PageControllerVer1.php

示例8: createImageKey

 public function createImageKey($user, $dblink)
 {
     if ($stm = $dblink->prepare("SELECT 2fa_imgname FROM  " . TABLE_USERS . " WHERE email = ?")) {
         $stm->execute(array($user));
         $row = $stm->fetch();
         $stm = NULL;
         $file = 'uploads/2fa/' . $row['2fa_imgname'];
     }
     $im = new Image();
     $imageclean = $im->loadLocalFile($file);
     $imagekey = $im->embedStegoKey($imageclean);
     $stegoKey = $im->stegoKey;
     $hash = password_hash($stegoKey, PASSWORD_DEFAULT);
     if ($stm = $dblink->prepare("UPDATE " . TABLE_USERS . " SET 2fa_hash = ? WHERE email = ?")) {
         $stm->execute(array($hash, $user));
         $stm = NULL;
     }
     if (ob_get_level()) {
         ob_end_clean();
     }
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=KeyImage.png');
     header('Content-Transfer-Encoding: binary');
     header('Expires: 0');
     header('Cache-Control: must-revalidate');
     header('Pragma: public');
     //header('Content-Length: ' . filesize($file));
     $ok = imagepng($imagekey);
     //, NULL, 9
     imagedestroy($imagekey);
     return $ok;
 }
开发者ID:semaster,项目名称:2FAuth-Steganography,代码行数:33,代码来源:AccountSetup2fa.php

示例9: passwordExists

function passwordExists($dbConn, $username, $password)
{
    $isValid = false;
    $dbQuery = "SELECT Password FROM USERS WHERE Username = '" . $username . "' LIMIT 1";
    FB::info('passwordExists() query: ' . $dbQuery);
    $dbRows = mysqli_query($dbConn, $dbQuery);
    $dbValues = mysqli_fetch_assoc($dbRows);
    $dbPassword = $dbValues['Password'];
    if (password_verify($password, $dbPassword)) {
        $isValid = true;
        FB::log('Password is valid!');
        // Check if the password needs a rehash.
        if (password_needs_rehash($dbPassword, PASSWORD_DEFAULT)) {
            FB::log('Rehashing password!');
            $dbPassword = password_hash($password, PASSWORD_DEFAULT);
            $dbQuery = "UPDATE USERS SET Password = '" . $dbPassword . "' WHERE Username = '" . $username . "'";
            FB::info('Password rehash query: ' . $dbQuery);
            $dbRows = mysqli_query($dbConn, $dbQuery);
            if ($dbRows) {
                FB::log('Password rehash successful!');
            } else {
                FB::error('Password rehash failed: ' . mysqli_error($dbConn));
            }
        }
    }
    return $isValid;
}
开发者ID:Jayme-LB,项目名称:prj666_public,代码行数:27,代码来源:selectQueries.php

示例10: insert_user

    public function insert_user()
    {
        $project_type = $this->input->post('project_type');
        $project_title = $this->input->post('project_title');
        $project_category = $this->input->post('project_category');
        $project_ = $this->input->post('project_');
        $project_ = $this->input->post('project_');
        $project_ = $this->input->post('project_');
        $project_ = $this->input->post('project_');
        $project_ = $this->input->post('project_');
        $project_ = $this->input->post('project_');
        $project_ = $this->input->post('project_');
        $keypass = 'du_du_chinhi_' . $password;
        $password_hash = password_hash($keypass, PASSWORD_BCRYPT);
        //--------------------------------------------------------------------------
        $sqlch1 = 'SELECT user_name FROM users WHERE user_name = ? OR email = ?';
        $sqlcheck1 = $this->db->query($sqlch1, array($username, $email));
        if ($this->db->affected_rows() > 0) {
            print_r('Number of affected rows:' . $this->db->affected_rows() . '</br>');
            echo 'Either the Username or email already exists.</br>';
        } else {
            $sql = 'INSERT INTO users ( first_name, last_name, email, user_name, password )	
				  VALUES (' . $this->db->escape($firstname) . ',
						  ' . $this->db->escape($lastname) . ',
						  ' . $this->db->escape($email) . ',
						  ' . $this->db->escape($username) . ',
						  ' . $this->db->escape($password_hash) . ')';
            $result = $this->db->query($sql);
        }
        //----------------------------------------------------------------------------
        return $result;
    }
开发者ID:ismael-rivera,项目名称:project-manati,代码行数:32,代码来源:model_projectcreate.php

示例11: agregarProductor

 public function agregarProductor()
 {
     $cadena = "1234567890abcd";
     for ($i = 0; $i <= 7; $i++) {
         $generador_password = substr($cadena, mt_rand(0, strlen($cadena) - 1), 1);
         $this->user_password .= $generador_password;
     }
     $this->user_password_hash = password_hash($this->user_password, PASSWORD_DEFAULT);
     $this->user_name = $this->nombre . $this->apellidop;
     $sql = "INSERT INTO usuarios(id_usuario, nombre, apellidop, apellidom) \r\n\t\t\t\tVALUES (null, '{$this->nombre}', '{$this->apellidop}', '{$this->apellidom}')";
     $insertUsuario = $this->db->consultaRetorno($sql);
     $sql = "SELECT id_usuario FROM usuarios";
     $selectUsuario = $this->db->consultaRetorno($sql);
     for ($i = 0; $row = $this->db->recorrer_assoc($selectUsuario); $i++) {
         $id_usuario = $row['id_usuario'];
     }
     $this->id_usuario = $id_usuario;
     $this->user_captcha = password_hash($_POST['user_captcha'], PASSWORD_DEFAULT);
     $sql = "INSERT INTO users(id_user, user_name, user_password_hash, user_email, user_captcha, idperfil, idusuario, user_registration_datetime)\r\n\t\t\tVALUES (null,'{$this->user_name}', '{$this->user_password_hash}', '{$this->user_email}', '{$this->user_captcha}', '{$this->tipo}', '{$this->id_usuario}', NOW())";
     $insertUser = $this->db->consultaRetorno($sql);
     if ($insertUsuario == true && $insertUser == true) {
         $this->link($this->user_name, $this->user_email, $this->user_password_hash, $this->user_captcha, $this->id_usuario);
     } else {
         $this->error[] = "<span class='label label-danger posicion'>Error Desconocido Intente De Nuevo.</span>";
         $sql = "DELETE FROM users WHERE idusuario = '{$this->id_usuario}'";
         $a = $this->db->consultaRetorno($sql);
         $sql = "DELETE FROM usuarios WHERE id_usuario = '{$this->id_usuario}'";
         $b = $this->db->consultaRetorno($sql);
     }
 }
开发者ID:comunidad-uimqroo,项目名称:Tianguis,代码行数:30,代码来源:Productores.php

示例12: registrationUser

 public function registrationUser()
 {
     $this->load->library(["form_validation"]);
     $this->load->helper("email");
     $this->form_validation->set_rules("tabUsername", "Username", "trim|required|min_length[5]|max_length[40] ");
     $this->form_validation->set_rules("tabPassword", "Password", "required|min_length[2]|max_length[60] ");
     $this->form_validation->set_rules("tabEmail", "Email", "trim|required|valid_email|max_length[254]");
     $message = [];
     if ($this->form_validation->run()) {
         $this->load->model("Users");
         $user_signin_data = ["login" => $this->input->post("tabUsername", true), "password" => password_hash($this->input->post("tabPassword"), PASSWORD_BCRYPT), "email" => $this->input->post("tabEmail")];
         $message = ["text" => "User " . $user_signin_data["login"]];
         if (empty($this->Users->getUserByLogin($user_signin_data["login"]))) {
             $this->Users->add($user_signin_data);
             $template = "loginForm";
             $message["text"] .= " succesfully registered";
         } else {
             $template = "signupForm";
             $message["text"] .= " already exist";
         }
     } else {
         $this->form_validation->set_error_delimiters("<div class='text-danger'>", "</div>");
         $template = "signupForm";
     }
     $this->loadTemplateView($template, $message);
 }
开发者ID:ilyafanat,项目名称:Users,代码行数:26,代码来源:Login.php

示例13: create

 public function create()
 {
     $firstname = $_POST['firstname'];
     $lastname = $_POST['lastname'];
     $email = $_POST['email'];
     $username = $_POST['username'];
     $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
     $conn = Db::getConnection();
     $sql = "SELECT *\n\t\t\t\tFROM users";
     $q = $conn->prepare($sql);
     $q->execute();
     $users = $q->fetchAll(\PDO::FETCH_ASSOC);
     $validator = new Validator();
     $error = $validator->validateRegisterForm($_POST, $users);
     //echo '<pre>'; var_dump($error); echo '</pre>';die();
     if ($error) {
         //echo '<pre>'; var_dump($error);die(); echo '</pre>';
         $html = new Html($this->controllerName);
         $html->error = $error;
         //echo '<pre>'; var_dump($html->error);die(); echo '</pre>';
         //;kweojn'dlfv'dlfkv
         $html->render('index');
     } else {
         $newUserSql = "INSERT INTO users\n\t\t\t(`firstname`, `lastname`, `email`, `username`, `password`, `admin`)\n\t\t\tVALUES\n\t\t\t('{$firstname}', '{$lastname}', '{$email}', '{$username}', '{$password}', '0')";
         $q = $conn->prepare($newUserSql);
         $q->execute();
         header('Location: /login/index');
     }
 }
开发者ID:Mikili975,项目名称:news_obj,代码行数:29,代码来源:RegisterController.php

示例14: testInsertMapped

 public function testInsertMapped()
 {
     $name = 'My Name';
     $this->mapped->insert(['email' => 'test+insertmapped@bapcat.com', 'password' => password_hash('password', PASSWORD_DEFAULT), 'user_name' => $name, 'age' => 5]);
     $user = $this->mapped->where('user_name', $name)->first();
     $this->assertSame($name, $user['user_name']);
 }
开发者ID:bapcat,项目名称:remodel,代码行数:7,代码来源:GatewayQueryMappedTest.php

示例15: create

 public function create($data)
 {
     $options = array('cost' => 11);
     $data['password'] = password_hash($data['password'], PASSWORD_BCRYPT, $options);
     parent::create($data);
     return $this->db->insert_id();
 }
开发者ID:vjlomocso,项目名称:meetthedocs,代码行数:7,代码来源:user_model.php


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