本文整理汇总了PHP中password函数的典型用法代码示例。如果您正苦于以下问题:PHP password函数的具体用法?PHP password怎么用?PHP password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了password函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: info
/**
* 修改个人信息
*/
public function info()
{
if (isset($_POST['dosubmit'])) {
$info = I('post.info');
if ($info['password'] == "") {
// 不修改密码
unset($info['password']);
unset($info['pwdconfirm']);
} else {
if (trim($info['password']) != trim($info['pwdconfirm'])) {
$this->error("两次密码不一致");
exit;
}
unset($info['pwdconfirm']);
$info['encrypt'] = create_randomstr();
$info['password'] = password($info['password'], $info['encrypt']);
}
if (M('admin')->save($info)) {
$this->success('更新成功');
} else {
$this->error('更新失败');
}
} else {
$where['userid'] = session('userid');
$data = M("admin")->where($where)->find();
$this->assign("data", $data);
//角色列表
$rolelist = M("admin_role")->select();
$this->assign("rolelist", $rolelist);
//-----End
$this->assign('data', $data);
$this->display();
}
}
示例2: register
public function register($username, $password)
{
if (empty($username) && empty($password)) {
return -2;
}
if ($this->session->has_userdata('uid')) {
return false;
}
if ($this->has_user($username)) {
return -1;
}
$password = password($password);
$this->db->set('`salt`', $password['salt']);
$this->db->set('`password`', $password['password']);
$this->db->set('`username`', $username);
$this->db->trans_start();
$this->db->insert('`Users`');
$id = $this->db->insert_id();
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
return false;
} else {
$this->db->trans_commit();
return $id;
}
}
示例3: action
public function action(\Baguette\Application $app, \Teto\Routing\Action $action)
{
if ($app->session->get('user_id', ['default' => false])) {
return new Response\RedirectResponse('/');
}
if (!$app->isTokenVerified) {
return new Response\RedirectResponse('/');
}
// systemは特殊なユーザーなのでログインできない
if (isset($_REQUEST['user'], $_REQUEST['password']) && $_REQUEST['user'] != 'system') {
$user = trim($_REQUEST['user']);
$pass = $_REQUEST['password'];
$query = 'SELECT * FROM `users` WHERE `slug` = ?';
$stmt = db()->prepare($query);
$stmt->execute([$user]);
if ($login = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$query = 'SELECT `password` FROM `user_passwords` WHERE `user_id` = ?';
$stmt = db()->prepare($query);
$stmt->execute([$login['id']]);
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($res && password($pass, $res['password']) === true) {
$app->refreshSession();
$app->session->set('user_id', $login['id']);
$app->session->set('user_slug', $login['slug']);
$app->session->set('user_name', $login['name']);
return new Response\RedirectResponse('/');
}
}
}
return new Response\TemplateResponse('login.tpl.html', ['user' => isset($_REQUEST['user']) ? $_REQUEST['user'] : null]);
}
示例4: action_edit
public function action_edit()
{
$id = $this->request->param('id');
if ($id != $this->user) {
$this->request->redirect(URL::base());
}
$view = View::factory('player_edit');
$view->realname = @real_name_from_id($id);
if ($_POST) {
$realname = @$_POST['realname'];
$current_password = @$_POST['current_password'];
$new_password = @$_POST['new_password'];
$confirm_password = @$_POST['confirm_password'];
if ($new_password) {
if (!Auth::check_password($current_password)) {
array_push($this->template->errors, "Password did not match password on file.");
}
if ($new_password != $confirm_password) {
array_push($this->template->errors, "New passwords did not match.");
}
if (empty($this->template->errors)) {
password(name_from_id($id));
}
}
if ($realname) {
DB::update('users')->set(array('realname' => $realname))->where('id', '=', $id)->execute();
}
$this->request->redirect('/player/view/2');
}
$this->template->content = $view;
}
示例5: memberEdit
/**
* 编辑用户
*/
public function memberEdit($id)
{
$member_db = M('member');
if (IS_POST) {
$data = I('post.info');
if ($data['password']) {
$passwordinfo = password($data['password']);
$data['password'] = $passwordinfo['password'];
$data['encrypt'] = $passwordinfo['encrypt'];
} else {
unset($data['password']);
}
$result = $member_db->where(array('memberid' => $id))->save($data);
if ($result) {
$this->success('修改成功');
} else {
$this->error('修改失败');
}
} else {
$member_type_db = M('member_type');
$info = $member_db->field('password, encrypt', true)->where(array('memberid' => $id))->find();
$typelist = $member_type_db->where(array('disabled' => '0'))->getField('typeid,typename', true);
$this->assign('info', $info);
$this->assign('typelist', $typelist);
$this->display('member_edit');
}
}
示例6: insertElement
function insertElement()
{
if (isset($_POST['ClassificationID'])) {
$ClassificationID = json_decode(sanitize($_POST['ClassificationID']));
}
if (isset($_POST['Element'])) {
$Element = json_decode(sanitize($_POST['Element']));
}
if (isset($_POST['AtomicMass'])) {
$AtomicMass = json_decode(sanitize($_POST['AtomicMass']));
}
$dbConn = mysqli_connect(server(), username(), password(), db("Elements"));
if ($dbConn->connect_error) {
die("Connection failed: " . $dbConn->connect_error);
}
$query = "INSERT INTO Elements ( ClassificationID, Element, AtomicMass ) " . "VALUES ( " . "" . $ClassificationID . ", " . "'" . $Element . "', " . "" . $AtomicMass . " );";
$result = $dbConn->query($query);
$return = new stdClass();
$return->querystring = (string) $query;
if ($result) {
$return->success = true;
} else {
$return->success = false;
}
return json_encode($return);
}
示例7: sendNotify
function sendNotify($userid, $msg, $link, $subject = null)
{
$umail = "noreply@wewanttotrade.com";
$ufname = "eDart";
$ulname = "User";
$domail = 1;
//PART I: Write to the database
$con = mysqli_connect(host(), username(), password(), mainDb());
$q = "INSERT INTO notify(`usr`,`date`,`message`,`link`) VALUES('" . mysqli_real_escape_string($con, $userid) . "','" . mysqli_real_escape_string($con, time()) . "','" . mysqli_real_escape_string($con, $msg) . "','" . mysqli_real_escape_string($con, $link) . "')";
//Insert a new row into the author's notifications
mysqli_query($con, $q);
//Execute
$user_call = new User(array("action" => "get", "id" => $userid));
$user_info = $user_call->run(true);
if (count($user_info) != 0) {
$user_info = $user_info[0];
$umail = $user_info["email"];
$ufname = ucwords($user_info["fname"]);
$ulname = ucwords($user_info["lname"]);
$domail = $user_info["do_mail"];
}
$greetings = array("Just wanted to let you know that:<br><br> %s. <br><br>That is all. Have a good rest of your day!", "In case you didn't know: <br><br>%s<br><br> Better go check it out.", "We hope you're having a good day! Just thought you might you want to know:<br><br> %s. <br><br>That is all. Carry on!", "Don't mean to break your flow, but we just thought you might want to know that<br><br> %s. <br><br>If you get the chance, you can check it out back at eDart. For now, live long and prosper!", "Hope your day is going splendidly! Just thought we'd let you know that:<br><br> %s. <br><br>When you have the time, check it out on eDart. Cool. For now, bye.");
$fullmsg = sprintf($greetings[rand(0, count($greetings) - 1)], $msg);
if ($subject == null) {
$subject = $msg;
}
//PART II: Send them an email
if ($domail == 1) {
sendMail($umail, $ufname, $ulname, $subject, $fullmsg, $link, "View on eDart");
}
}
示例8: callback
/**
* 授权回调地址
*/
public function callback($type = null, $code = null)
{
if (!$type || !$code) {
$this->error('参数错误');
}
$type = strtolower($type);
try {
$sns = ThinkOauth::getInstance($type);
} catch (\Exception $e) {
$this->error('登录失败');
}
$extend = null;
//腾讯微博需传递的额外参数
if ($type == 'tencent') {
$extend = array('openid' => I('get.openid'), 'openkey' => I('get.openkey'));
}
try {
$token = $sns->getAccessToken($code, $extend);
} catch (\Exception $e) {
$this->error('登录失败');
}
//调用不同的登录方式
$data = self::$type($sns);
if (!$data) {
$this->error('登录失败');
}
$member_db = M('member');
$member_oauth_db = M('member_oauth');
//如果用户没有注册则先进行注册
$oauthInfo = $member_oauth_db->where(array('type' => $data['type'], 'openid' => $data['openid']))->find();
if (!$oauthInfo) {
$memberInfo = $member_db->where(array('username' => $data['username']))->find();
if (!$memberInfo) {
//添加一个随机密码,防止出现用户名密码都为空的情况
$passwordinfo = password(rand(00, 999999));
$add = array('username' => $data['username'], 'password' => $passwordinfo['password'], 'encrypt' => $passwordinfo['encrypt'], 'typeid' => 2, 'regtime' => time(), 'lastloginip' => get_client_ip(0, true), 'lastlogintime' => time());
$memberid = $member_db->add($add);
} else {
$memberid = $memberInfo['memberid'];
}
if (!$memberid) {
$this->error('登录失败');
}
unset($data['username']);
$data = array_merge($data, array('memberid' => $memberid, 'addtime' => time()));
$id = $member_oauth_db->add($data);
if (!$id) {
$this->error('登录失败');
}
$oauthInfo = $data;
}
//修改登陆时间
$member_db->where(array('memberid' => $oauthInfo['memberid']))->save(array('lastloginip' => get_client_ip(0, true), 'lastlogintime' => time()));
cookie('member_id', $oauthInfo['memberid']);
cookie('member_name', $oauthInfo['nick']);
cookie('member_head', $oauthInfo['head']);
cookie('member_link', $oauthInfo['link']);
$this->success('登录成功', U('Home/Index/index'));
}
示例9: editPassword
/**
* 修改密码
*/
public function editPassword($userid, $password)
{
$userid = intval($userid);
if ($userid < 1) {
return false;
}
$passwordinfo = password($password);
return $this->where(array('userid' => $userid))->save($passwordinfo);
}
示例10: createUser
function createUser($pdo, $username, $password)
{
$truncate = "TRUNCATE TABLE `security_users`; TRUNCATE TABLE `security_user_types`;";
$insertSQL = "INSERT INTO `security_users` (id, identification_no, country_id, username, password, first_name, middle_name, last_name, gender, super_admin, status, created_user_id, created) VALUES (%s)";
$values = array(1, "'" . 'S123' . "'", 1, "'" . $username . "'", "'" . password($password) . "'", "'System'", "''", "'Administrator'", "'M'", 1, 1, 1, 'NOW()');
$insertTypeSQL = "INSERT INTO `security_user_types` (id, security_user_id, type) VALUES (1, 1, 1);";
$pdo->exec($truncate);
$pdo->exec(sprintf($insertSQL, implode(', ', $values)));
$pdo->exec($insertTypeSQL);
}
示例11: edit_password
public function edit_password($userid, $password){
$userid = intval($userid);
if($userid < 1) return false;
if(!is_password($password))
{
showmessage(L('pwd_incorrect'));
return false;
}
$passwordinfo = password($password);
return $this->db->update($passwordinfo,array('userid'=>$userid));
}
示例12: register
private static function register($slug, $name, $password) : array
{
$query = 'INSERT INTO `users` (`slug`, `name`) VALUES(?, ?)';
$stmt = db()->prepare($query);
$stmt->execute([$slug, $name]);
$id = db()->lastInsertId();
$query = 'INSERT INTO `user_passwords` VALUES(?, ?)';
$stmt = db()->prepare($query);
$stmt->execute([$id, password($password)]);
return ['id' => $id, 'name' => $name, 'slug' => $slug];
}
示例13: postLogin
public function postLogin(\Illuminate\Http\Request $request)
{
$this->validate($request, ['email' => ['required', 'regex:/^\\w+@\\w+(\\.\\w+)+$/'], 'password' => ['required', 'regex:/^[\\S]{6,16}$/']]);
$user = DB::table('user')->whereRaw('email = ? AND password = ?', [Request::input('email'), password(Request::input('password'))])->first();
if ($user) {
Session::put('user', (array) $user);
return redirect('admin');
} else {
return redirect()->back()->withErrors(['用户名或密码错误']);
}
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (isset($_SESSION['Admin'])) {
if ($_SESSION['Admin'] == $_SERVER['REMOTE_ADDR'] . 'passwordHash' . password()) {
return $next($request);
} else {
unset($_SESSION['Admin']);
return redirect('/');
}
}
return redirect('/');
}
示例15: edit_password
/**
* 修改密码
* @param unknown $userid 用户ID
* @param unknown $password 密码
* @return boolean
*/
public function edit_password($userid, $password)
{
$userid = intval($userid);
if ($userid < 1) {
return false;
}
if (!is_password($password)) {
return false;
}
$passwordinfo = password($password);
return $this->where('userid=' . $userid)->save($passwordinfo);
}