- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些 php 脚本,使我的用户能够使用电子邮件创建帐户。然后,他设置了一个经过哈希处理的密码,生成了一个盐并将其存储在我的数据库中。现在我正在重置密码,工作正常,但新密码(更改密码,即使其正确的密码由于注册时使用的盐和哈希而无法验证电子邮件)
下面是我用来加密 user_password 的哈希函数
public function hashFunction($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
这是我的重置密码(更改密码,但更改后的密码无法验证)
<?php
if(isset($_POST["reset-password"])) {
require_once('connect.php');
$sql = "UPDATE `oasisdb`.`registration_data` SET `user_password` = '" . ($_POST["user_password"]). "' WHERE `registration_data`.`name` = '" . $_GET["name"] . "'";
$result = mysqli_query($con,$sql);
$success_message = "Password is reset successfully.";
}
?>
<link href="demo-style.css" rel="stylesheet" type="text/css">
<script>
function validate_password_reset() {
if((document.getElementById("user_password").value == "") && (document.getElementById("confirm_password").value == "")) {
document.getElementById("validation-message").innerHTML = "Please enter new password!"
return false;
}
if(document.getElementById("user_password").value != document.getElementById("confirm_password").value) {
document.getElementById("validation-message").innerHTML = "Both password should be same!"
return false;
}
return true;
}
</script>
<form name="frmReset" id="frmReset" method="post" onSubmit="return validate_password_reset();">
<h1>Reset Password</h1>
<?php if(!empty($success_message)) { ?>
<div class="success_message"><?php echo $success_message; ?></div>
<?php } ?>
<div id="validation-message">
<?php if(!empty($error_message)) { ?>
<?php echo $error_message; ?>
<?php } ?>
</div>
<div class="field-group">
<div><label for="Password">Password</label></div>
<div>
<input type="password" name="user_password" id="user_password" class="input-field"></div>
</div>
<div class="field-group">
<div><label for="email">Confirm Password</label></div>
<div><input type="password" name="confirm_password" id="confirm_password" class="input-field"></div>
</div>
<div class="field-group">
<div><input type="submit" name="reset-password" id="reset-password" value="Reset Password" class="form-submit-button"></div>
</div>
</form>
这是我的 mysql 表
CREATE TABLE `registration_data` (
`id` int(255) NOT NULL,
`name` varchar(150) NOT NULL,
`email` varchar(150) NOT NULL,
`user_password` varchar(80) NOT NULL,
`salt` varchar(10) NOT NULL,
`gender` varchar(50) NOT NULL,
`phone` varchar(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
最后这是我的login.php
<?php
require_once 'update_user_info.php';
$db = new update_user_info();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['email']) && isset($_POST['password'])) {
// receiving the post params
$email = $_POST['email'];
$password = $_POST['password'];
// get the user by email and password
$user = $db->VerifyUserAuthentication($email, $password);
if ($user != false) {
// use is found
$response["error"] = FALSE;
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["phone"] = $user["phone"];
$response["user"]["gender"] = $user["gender"];
echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = TRUE;
$response["error_msg"] = "Wrong E-mail or Password. Please try again!";
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters E-mail and Password is missing!";
echo json_encode($response);
}
?>
这就是注册时使用哈希的方式
public function StoreUserInfo($name, $email, $password, $gender, $phone) {
$hash = $this->hashFunction($password);
$user_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$stmt = $this->conn->prepare("INSERT INTO registration_data(name, email, user_password, salt, gender, phone) VALUES(?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssss", $name, $email, $user_password, $salt, $gender, $phone);
$result = $stmt->execute();
$stmt->close();
最佳答案
这是我用于密码重置页面的代码。
这包括密码强度验证。
也许这会对您有所帮助,您可以随意使用它。
您应该自己将其与您的代码合并。
我使用 base64
编码字符串来放入用户信息,例如电子邮件地址及其是否有效的代码。
<meta charset="UTF-8">
<?php
require("mysql_config.php");
session_start();
$melding = "";
if (isset($_GET['usr']))
{
$passwordresetcode = base64_decode($_GET['usr']);
}
else
{
$passwordresetcode = '';
}
$strings = explode(', ', $passwordresetcode);
$email = $strings[0];
$code = $strings[1];
if(isset($_POST['resetpass'])){
$query_login = "
UPDATE users SET
salt = :salt,
password = :password
WHERE email = '".$email."'
";
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
$password = $_POST['password'];
$query_params = array(
':salt' => $salt,
':password' => hash('sha256', $password . $salt)
);
try {
$stmt11 = $db->prepare($query_login);
$result = $stmt11->execute($query_params);
}
catch(PDOException $ex){ die("Failed to run query 2: " . $ex->getMessage()); }
header("Location: login.php"); /* Redirect browser */
}
else{
$code = str_replace(' ', '', $code);
//$code = trim($code," ");
$stmt = $db->prepare("
SELECT *
FROM users
WHERE email = '$email'
");
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row)
{
?>
<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
<div id="password_reset_form" class="col-X-6 col-xs-12" style="margin: 0 auto;">
<h2>New password</h2>
<form method="POST">
<input type="password" id="pwd" name="password" minlength='8' autocomplete="off" placeholder="Password">
<div id="progress">
<div id="progress-bar"></div>
</div>
<input type="password" id="repeat_pwd" name="repeatpassword" minlength='8' autocomplete="off" placeholder="Repeat Password">
<div id="match" style="background: lightblue;">
</div><br/>
<input type="submit" disabled id="resetpassword" onclick="hide_form()" name="resetpass" class="button disabled" value="Verstuur">
<br/><br/>
</form>
</div>
<?php
}
}
else{
echo 'No user found!';
}
?>
<script>
function hide_form(){
$('#password_reset_form').css( "display", "none" );
}
function check(score){
if($("#pwd").val() == $("#repeat_pwd").val()){
$("#match").html("Passwords do not match!");
$("#match").css("background-color", "#DFF2BF");
if(score == 5){$("#resetpassword").prop('disabled', false); $("#resetpassword").removeClass("disabled");}else{$("#resetpassword").prop('disabled', true); $("#resetpassword").addClass("disabled"); $("#match").html("Password not strong enough!"); $("#match").css("background-color", "rgb(255, 182, 119)");}
}
else{
$("#match").html("Passwords do not match!");
$("#match").css("background-color", "#FFBABA");
$("#resetpassword").prop('disabled', true);
$("#resetpassword").addClass("disabled");
}
}
var score = 0;
function update_bar( element, password ) {
var desc = [{'width':'0px'}, {'width':'20%'}, {'width':'40%'}, {'width':'60%'}, {'width':'80%'}, {'width':'100%'}];
var descClass = ['', 'progress-bar-danger', 'progress-bar-danger', 'progress-bar-warning', 'progress-bar-warning', 'progress-bar-success'];
score = 0;
element.removeClass();
if(password.length > 10) {
score++;
}
if(password.length > 6) {
score++;
}
if ( (password.match(/[a-z]/)) && (password.match(/[A-Z]/))) {
score++;
}
if (password.match(/\d+/)) {
score++;
}
if (password.match(/.[/,\\,!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) {
score++;
}
if (password.length > 8) {
score++;
}
if(score > 5){
score = 5;
}
element.addClass( descClass[score] );
element.css( desc[score] );
check(score);
}
$("#pwd").keyup(function() {
update_bar( $( "#progress-bar" ), $("#pwd").val() );
});
$("#pwd").bind('paste', function(event) {
update_bar( $( "#progress-bar" ), $("#pwd").val() );
});
$("#pwd").bind('change', function(event) {
update_bar( $( "#progress-bar" ), $("#pwd").val() );
});
$("#repeat_pwd").keyup(function() {
check(score);
});
$("#repeat_pwd").bind('paste', function(event) {
check(score);
});
$("#repeat_pwd").bind('change', function(event) {
check(score);
});
</script>
<style>
form {
max-width: 400px;
padding: 1em;
}
h2{
text-align: center;
vertical-align: middle;
}
input {
display: block;
width: 100%;
box-sizing: border-box;
padding: 6px;
border: 1px solid #ddd;
}
#progress {
height: 5px;
border: 1px solid #ddd;
margin-bottom: 10px;
}
#progress-bar {
width: 0%;
height: 100%;
transition: width 500ms linear;
}
#match{
height: 30px;
margin-top: 10px;
border: 1px solid #ddd;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 300;
border-radius: 3px 3px 3px 3px;
line-height: 30px;
text-align: center;
}
.progress-bar-danger {
background: #d00;
}
.progress-bar-warning {
background: #f50;
}
.progress-bar-success {
background: #080;
}
#password_reset_form{
margin: 0 auto;
display: table;
margin-top: 40px;
}
#password_reset_form img{
margin: 0 auto;
display: table;
}
#password_reset_form form{
margin: 0 auto;
display: block;
}
body{
font-family: 'Open Sans';
}
</style>
关于php - 如何重置密码,盐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59244115/
Internal Server Error: /admin/account/customuser/add/ Traceback (most recent call last): File "C:\
有问题!虽然我发现几乎相似的线程但没有帮助:( 我编写了一个 php 脚本来从我的 MySQL 数据库中获取注册用户的数量。该脚本在我的本地主机上运行良好;它使用给定的用户名、密码和主机名,分别是“r
我正在做一项基于密码的作业,我将 key 和消息放在单独的数组中。我想创建第三个数组,其中包含围绕消息大小的 key ,如下所示: message keykeyk 我已经在这个问题上苦苦挣扎了一段时间
我的几个客户要求我实现图形密码检查器,例如 关于如何实现这种 UI 有什么想法吗? 最佳答案 试着看看这个:https://code.google.com/p/android-lockpattern/
我正在使用 MAMP,每次登录 phpMyAdmin 时,都会收到以下错误/警告消息: the configuration file now needs a secret passphrase (bl
我正在尝试通过将 Visual Studio 2013 连接到我的测试机来调试 WDF 驱动程序。它创建一个名为 WDKRemoteUser 的用户,并在进行测试时尝试自动登录。有人知道这个用户的密码
使用具有指定用户名和密码的 SVN 提交。我希望服务器抛出错误;所以我可以告诉我的用户他/她的密码错误。 相反,在使用错误密码提交后: svn commit "test_file.txt" --use
我正在尝试实现 friend 推荐。 它从节点“你”开始。而且,我想找到节点“安娜”。 换句话说,这是我的两个或更多 friend 共同认识的人。上面的示例节点是 Anna。 如果您的帮助,我将不胜感
我都尝试过 wget --user=myuser --password=mypassword myfile 和 wget --ftp-user=myuser --ftp-password=mypass
我的一位用户提示说,每当他尝试使用默认管理界面(Django 的管理员)添加新用户(auth.User)时,新用户名和密码都会自动填充他自己的。 问题是他在登录时要求 Firefox 记住他的用户名/
我们正在开发一款应用(当然)用于应用购买 (IAP)。我已完成指南中的所有操作以启用 iap,并且一切正常,直到我想要购买为止。 部分代码: MainViewController.m -(vo
我试图创建两个可选匹配项的并集(如下所示),但我得到的不是并集,而是两者的交集。我应该如何更改此查询以获得所需的联合? optional match (a:PA)-[r2:network*2]-(b:
我想将Ansible用作另一个Python软件的一部分。在该软件中,我有一个包含其用户名/密码的主机列表。 有没有一种方法可以将SSH连接的用户/密码传递给Ansible ad-hoc命令或以加密方式
嗨,我在使用xampp的Apache Web服务器上收到错误500。直到我使用.htaccess,.htpasswd文件,错误才出现。我搜索了,但找不到语法错误。我只有1张图片和要保护的索引文件。以下
我一直使用它来编辑用户帐户信息: $this->validate($request, [ 'password' => 'min:6', 'password_confirmation'
我需要使用InstallUtil来安装C# Windows服务。我需要设置服务登录凭据(用户名和密码)。这一切都需要默默地完成。 有没有办法做这样的事情: installutil.exe myserv
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
如果我有一个随机的、16 个字符长的字母数字盐(不同大小写),它是为每个用户生成和存储的,我是否还需要一个站点范围的盐? 换句话说,这样好吗? sha1($user_salt . $password)
我正在开发一个空白程序,该程序将允许用户创建一个帐户,以便他们可以存储其余额和提款/存款。用户输入用户名和密码后,如何存储这些信息以便用户可以登录并查看其余额?我不一定要尝试使其非常安全,我只是希望能
我正在尝试寻找一种通用方法来搜索没有链接到另一个节点或节点集的节点或节点集。例如,我能够找到特定类型(例如 :Style)的所有节点,这些节点以某种方式连接到一组特定的节点(例如 :MetadataR
我是一名优秀的程序员,十分优秀!