本文整理汇总了PHP中Hash::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::create方法的具体用法?PHP Hash::create怎么用?PHP Hash::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($static = false)
{
$form = new Form();
$form->post('login')->val('blank')->post('password')->val('blank');
if (!$form->submit()) {
// Error
$this->_error($static);
return false;
}
$data = $form->fetch();
$login = $data['login'];
$password = Hash::create('sha256', $data['password'], PASS_HASH_KEY);
$query = "SELECT userid, login, role FROM user WHERE login = :login AND password = :password";
if (!($result = $this->db->select($query, array(':login' => $login, ':password' => $password)))) {
$this->_error($static);
return false;
}
Session::init();
Session::set('userid', $result[0]['userid']);
Session::set('login', $result[0]['login']);
Session::set('role', $result[0]['role']);
Session::set('loggedIn', true);
if ($static) {
header('location:' . URL . 'dashboard');
}
echo json_encode('success');
}
示例2: auth
public function auth()
{
$user = new User();
$username = $_POST['username'];
$password = Hash::create('md5', $_POST['password'], HASH_SALT_KEY);
$data = $user->getUser($username, $password);
foreach ($data as $value) {
$this->user = $value->get('nama_user');
$this->nama = $value->get('namaPegawai');
$this->role = $value->get('role');
$this->bagian = $value->get('bagian');
}
$int = count($data);
$this->view->error = array();
if ($int > 0) {
@Session::createSession();
Session::set('loggedin', true);
Session::set('user', $this->user);
Session::set('nama', $this->nama);
Session::set('role', $this->role);
Session::set('bagian', $this->bagian);
$log = new Log();
$log->addLog(Session::get('user'), 'LOGIN', '');
unset($log);
// header('location:../home');
echo json_encode(array('status' => 'success'));
} else {
// $this->view->error['invalid'] = 'Akun tidak ditemukan';
//header('location:../login');
// $this->view->render('login/index');
// echo 'Akun tidak ditemukan';
echo json_encode(array('status' => 'error', 'message' => 'Akun tidak ditemukan'));
}
}
示例3: run
public function run()
{
/*
* md5 is a 32 bit hash
*/
$statement = $this->db->prepare("SELECT id, role FROM users WHERE login = :user AND password = :pass");
$statement->execute(array(':user' => $_POST['user'], ':pass' => Hash::create('sha256', $_POST['pass'], HASH_KEY)));
/*
* The Obj returned by $statement was 'Array of Arrays'
*/
$result = $statement->fetchAll();
//$statement returns an Array of objects
//print_r($result);
//echo '</br>';
$data = $result['0'];
//print_r($data);
//echo '</br>role='.$data['role'];
$count = $statement->rowCount();
if ($count > 0) {
//log in the user
Session::init();
Session::set('userid', $data['id']);
Session::set('role', $data['role']);
Session::set('loggedIn', true);
header('location: ../dashboard');
} else {
//show an error
header('location: ../login');
}
}
示例4: run
public function run()
{
$login = $_POST['login'];
$password = $_POST['password'];
/* PDO */
$res = $this->db->prepare("SELECT userid, role FROM users WHERE\n login = :login AND password = :password");
$res->execute(array(':login' => $login, ':password' => Hash::create(HASH_METHOD, $password, HASH_PASSWORD_KEY)));
// $data = $res->fetchAll();
$count = $res->rowCount();
/* mysqli */
/*$res = $this->db->prepare("select id from users
where login = ?
and password = MD5(?)");
$res->bind_param("ss",$login,$password);
$res->execute();
$res->bind_result($ret);
$res->fetch();*/
$data = $res->fetch();
if ($count > 0) {
//login
Session::init();
Session::set('role', $data['role']);
Session::set('loggedIn', true);
Session::set('userid', $data['userid']);
header('Location:../dashboard');
exit;
} else {
//show an Error
header('Location:../login');
exit;
}
// return $ret;
}
示例5: editSave
public function editSave($data)
{
$myTable = 'users';
$postData = array('login' => $data['login'], 'password' => Hash::create('sha256', $data['password'], HASH_PASSWORD_KEY), 'role' => $data['role']);
$where = "`id` = {$data['id']}";
$this->db->update($myTable, $postData, $where);
}
示例6: changePass
function changePass()
{
Auth::handleClientLogin();
$data['client_id'] = Session::get('client_id');
$client_pass = $this->model->getPass();
$client_old_pass = Hash::create('md5', $_POST['client_old_pass'], HASH_PASSWORD_KEY);
if ($client_pass[0]['client_pass'] != $client_old_pass) {
echo -2;
exit;
}
if ($_POST['client_old_pass'] == '' || $_POST['client_pass_1'] == '' || $_POST['client_pass_2'] == "") {
echo -1;
exit;
}
if (strlen($_POST['client_pass_1']) < 6 || strlen($_POST['client_pass_2']) < 6) {
echo 0;
exit;
}
if ($_POST['client_pass_1'] != $_POST['client_pass_2']) {
echo 1;
exit;
}
$data['client_pass'] = Hash::create('md5', $_POST['client_pass_2'], HASH_PASSWORD_KEY);
$this->model->changePass($data);
}
示例7: testCreate
/**
* @covers ::__construct
* @covers ::create
* @covers ::set
* @covers ::has
* @covers ::get
* @covers ::_filterName
*/
public function testCreate()
{
$this->assertInstanceOf(__NAMESPACE__ . '\\Hash', $hash = Hash::create(Hash::NO_CASE_SENSITIVE, ['a' => 'b'], ['c' => 'd'], ['hoge' => 'XYZ'], ['hOgE' => 'ABC']));
$this->assertTrue($hash->has('HoGe'));
$this->assertEquals('ABC', $hash->get('HoGe'));
$this->assertEquals('not_exists', $hash->get('NotExists', 'not_exists'));
return $hash;
}
示例8: validateUser
public function validateUser($userName, $password, AuthenticationManager $authenticationManager)
{
ResultHelper::whenEqual($password, null, AppLabelUtil::$ERROR_USER_NOT_FOUND, HttpStatusCode::badRequest());
$user = $this->userService->validateUser($userName, $password);
ResultHelper::whenEmpty($user, AppLabelUtil::$ERROR_USER_NOT_FOUND, HttpStatusCode::unauthorized());
$token = Hash::create("sha256", mcrypt_create_iv(64, MCRYPT_DEV_URANDOM), HASH_USER_TOKEN_KEY);
$authenticationManager->createValidationToken($user->getId(), $user->getRole()->getName(), $token);
return $this->userMapper->mapUserToDto($user, $token);
}
示例9: editSave
public function editSave($data)
{
$postData = array('login' => $data['login'], 'password' => Hash::create(HASH_METHOD, $data['password'], HASH_PASSWORD_KEY), 'role' => $data['role'], 'userid' => $data['userid']);
$this->db->update('users', $postData, "`userid`= {$data['userid']}");
$res = $this->db->prepare('UPDATE users
SET `login`=:login, `password`=:password, `role`=:role
WHERE userid=:userid
');
$res->execute(array(':login' => $data['login'], ':password' => Hash::create(HASH_METHOD, $data['password'], HASH_PASSWORD_KEY), ':role' => $data['role'], ':userid' => $data['userid']));
}
示例10: createResetToken
public function createResetToken(User $user)
{
ResultHelper::whenEmpty($user->getEmail(), AppLabelUtil::$ERROR_USER_NO_EMAIL, HttpStatusCode::internalServerError());
$tokenHash = Hash::create("sha256", mcrypt_create_iv(64, MCRYPT_DEV_URANDOM), HASH_GENERAL_KEY);
$this->mailService->setMailHeading(array($user->getEmail() => $user->getFirstName() . " " . $user->getLastName()));
$this->mailService->setBody("Instellen van uw wachtwoord", "Beste gebruiker, gelieve de volgende link te gebruiken om uw wachtwoord in te stellen: " . URL . "#/reset/token/" . $tokenHash);
$this->mailService->sendMail();
$resetToken = $this->resetTokenFactory->createResetToken($user->getId(), $tokenHash);
$this->resetTokenDao->create($resetToken);
}
示例11: editSave
public function editSave($data)
{
$password = Hash::create('sha256', $data['password'], HASH_PASSWORD_KEY);
$user = new User();
$existingUser = $user->findById($data['id']);
$existingUser->setId($data['id']);
$existingUser->setLogin($data['login']);
$existingUser->setPassword($password);
$existingUser->setRole($data['role']);
$existingUser->update(true);
}
示例12: editSave
public function editSave($id)
{
//Form is posted from the Edit page, Do the Error check
$data = array();
$data['id'] = $id;
$data['login'] = $_POST['login'];
$data['password'] = Hash::create('sha256', $_POST['password'], HASH_KEY);
$data['role'] = $_POST['role'];
//Do the Error checking
$this->model->RunEditSave($data);
header('location: ' . URL . 'users');
}
示例13: update
/**
* update
* @param String $table A name of table to insert into
* @param String $data An associative array
* @param String $where the WHERE query part
*/
public function update($table, $data, $where)
{
ksort($data);
$data['password'] = Hash::create('md5', $data['password'], HASH_KEY);
$arrTemp = array();
foreach ($data as $key => $value) {
$arrTemp[$key] = $key . "=" . "'{$value}'";
}
$fieldValues = implode(",", array_values($arrTemp));
$pquery = $this->prepare("UPDATE {$table} SET {$fieldValues} WHERE {$where}");
$pquery->execute();
}
示例14: clientLogin
function clientLogin($data)
{
$sql = "SELECT client_id,client_username FROM client WHERE client_email = :client_email AND client_pass = :client_pass AND client_is_active = 1";
$client = array(':client_email' => $data['email_login'], ':client_pass' => Hash::create('md5', $data['pass_login'], HASH_PASSWORD_KEY));
$result = $this->db->select($sql, $client);
if (isset($result[0]['client_id'])) {
Session::init();
Session::set('client_id', $result[0]['client_id']);
Session::set('client_username', $result[0]['client_username']);
}
echo json_encode($result);
}
示例15: save
public function save()
{
$password = $this->model->generate_password();
$this->model->mail($_POST['email'], $_POST['name'], $password);
$data = array("name" => $_POST['name'], "email" => $_POST['email'], "password" => Hash::create($password));
if ($_POST['type'] == 'create') {
$this->model->create($data);
}
if ($_POST['type'] == 'edit') {
$this->model->edit($data, $_POST['id']);
}
header("Location: " . URL . "user");
}