簡體   English   中英

PHP更新用戶-錯誤“密碼不匹配”

[英]PHP update user - error “password didnt match”

由於我在php中是新的,並且了解的不多,所以我的問題是我檢查了代碼中的每種語法,即使數據庫中的舊密碼在我的舊密碼字段中匹配,我仍然收到此錯誤“密碼不匹配”。希望您能為我提供幫助,對不起,我的格式不好,我還是一個新手。

這是我的代碼。

<?php


$submit = strip_tags($_POST['submit']); 

$username = strtolower(strip_tags($_POST['username']));


$oldpassword = strip_tags($_POST['oldpassword']);

$newpassword = strip_tags($_POST['newpassword']);

$firstname = strip_tags($_POST['first']);

$lastname = strip_tags($_POST['last']);

$gender = strip_tags($_POST['gender']);

$address = strip_tags($_POST['address']);

$zipcode = strip_tags($_POST['zip']);

$contact = strip_tags($_POST['con']);

$email = strip_tags($_POST['mail']);

error_reporting(0);



if($submit)
{

if($username&& $oldpassword && $newpassword && $firstname && $lastname && $address && $zipcode && $contact && $email)
{

$connect = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("brightlights") or die(mysql_error());

$updatecheck = mysql_query("SELECT * FROM tb_user WHERE username='$username'");
$count = mysql_num_rows($updatecheck);
if($count<=1)
{

if($password==($oldpassword))
{

mysql_query("UPDATE tb_user SET
                username = '$username',
                password = '$newpassword',
                Firstname = '$firstname',
                Lastname = '$lastname',
                gender = '$gender',
                address = '$address',
                zipcode = '$zipcode',
                contact = '$contact',
                email = '$email'
                WHERE username='".$_SESSION['username']."'");
                $_SESSION['username'] = $username;
                $_SESSION['password'] = $newpassword;
                $_SESSION['Firstname'] = $firstname;
                $_SESSION['Lastname'] = $lastname;
                $_SESSION['gender'] = $gender;
                $_SESSION['address'] = $address;
                $_SESSION['zipcode'] = $zipcode;
                $_SESSION['contact'] = $contact;
                $_SESSION['email'] = $email;
                session_write_close();
                echo "Succesfully Updated!";

            }else
                echo "Password not match!";
        }else
            echo "Username already Taken!";
    }else
        echo "Please fill up all form!";



}           
?>

與其通過請求檢索舊密碼,不如從數據庫中檢索舊密碼。

$query = mysql_query("SELECT password FROM tb_user WHERE username='$username' LIMIT 1");
$count = mysql_num_rows($query);

if($count==1)
{
  $result = mysql_fetch_assoc($query);
  if($newpassword==$result["password"])
  {
......

作為旁注。 在保留/比較密碼時,請始終對密碼進行哈希處理。 本文介紹了其中的大部分內容:

http://phpsec.org/articles/2005/password-hashing.html

采用

if($newpassword==$oldpassword)

在狀態

if($password==($oldpassword))

我認為您的問題將得到解決。 並嘗試從數據庫獲取oldpass。

只需打印密碼和舊密碼並檢查內容即可:

print($password);
print($oldpassword);

if($password==($oldpassword))

為什么封裝舊密碼?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM