2014-11-25 101 views
-2

我需要一些幫助。我目前正在開發我公司的網站,並且一切都很順利,直到我測試了管理員帳戶(我使用的)的更改密碼功能。我已經爲擁有自己更改密碼功能的員工設置了一個單獨的帳戶。我的問題是每當我更改密碼時,它也會將職員帳戶的密碼更改爲同一個密碼。更改管理員帳戶的密碼也會影響員工帳戶

下面是密碼的變化PHP代碼:

<?php 
session_cache_limiter("private"); 
$cache_limiter = session_cache_limiter(); 
session_cache_expire(180); 
$cache_expire=session_cache_expire(); 
session_start(); 
if(isset($_SESSION['acc_uname'],$_SESSION['acc_pword'])) 
{ 
$acc_uname=$_SESSION['acc_uname']; 
$acc_pword=$_SESSION['acc_pword']; 
require_once('/home/a9440778/public_html/registration/connect.php'); 
function escape_data($data) 
{ 
global $dbc; 
if(ini_get('magic_qoutes_gpc')) 
{ 
$data=stripslashes($data); 
} 
return mysql_real_escape_string($data,$dbc); 
} 
error_reporting(E_ALL & ~E_NOTICE); 
echo"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> 
<html xmlns='http://www.w3.org/1999/xhtml'> 
<head> 
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> 
<title> 
Natuna Scean Manpower Corporation 
</title></head>"; 
if(empty($_POST['acc_pword1'])) 
{ 
$acc_pword1=false; 
echo"<b>Old Password</b> Contains null value<br>"; 
$retry=1; 
} 
else if($_POST['acc_pword1_err']=='1') 
{ 
$acc_pword1=false; 
echo"<b>Old Password</b> Contains invalid value<br>"; 
$retry=1; 
} 
else 
{ 
$acc_pword1=md5(escape_data($_POST['acc_pword1'])); 
} 
if(empty($_POST['acc_pword2'])) 
{ 
$acc_pword2=false; 
echo"<b>New Password</b> Contains null value<br>"; 
$retry=1; 
} 
else if($_POST['acc_pword2_err']=='1') 
{ 
$acc_pword2=false; 
echo"<b>New Password</b> Contains invalid value<br>"; 
$retry=1; 
} 
else 
{ 
$acc_pword2=md5(escape_data($_POST['acc_pword2'])); 
} 
if(empty($_POST['acc_pword3'])) 
{ 
$acc_pword3=false; 
echo"<b>Retype Password</b> Contains null value<br>"; 
$retry=1; 
} 
else if($_POST['acc_pword3_err']=='1') 
{ 
$acc_pword3=false; 
echo"<b>Retype Password</b> Contains invalid value<br>"; 
$retry=1; 
} 
else 
{ 
$acc_pword3=md5(escape_data($_POST['acc_pword3'])); 
} 
if($acc_pword3!=$acc_pword2) 
{ 
$acc_pword3=false; 
$acc_pword2=false; 
echo"<b>New Passwords</b> do not match each other<br>"; 
$retry=1; 
} 
if($acc_pword1!=$acc_pword) 
{ 
$acc_pword1=false; 
echo"<b>Old Password</b> does not match<br>"; 
$retry=1; 
} 
if($retry=='1') 
{ 
echo"<br><br><a href='javascript:history.go(-1)' target='middle'>retry encoding</a>"; 
} 
else 
{ 
echo"<script> 

alert('Password Update Successful!'); 
window.location='http://natunascean.site88.net/admin/adminhome.php'; 
</script>"; 

/* echo" 
<br><b>You had successfully updated your account</b><br><br> 
<a href='' onclick='window.adminhome.php.reload(true)'>Done</a>"; */ 
$query=mysql_query("update account set acc_pword='$acc_pword2' where acc_pword='$acc_pword';")or die("JBSOFTWARES 1".mysql_error()); 
$_SESSION['acc_uname']="$acc_uname"; 
$_SESSION['acc_pword']="$acc_pword2"; 
$_SESSION['acc_type']="$acc_type"; 
} 
} 
else 
{ 
echo"<center><br><br><img src='ops.png'></center>"; 
} 
?> 

我剛纔編輯的「window.location的」和零件的onClick其中adminhome.php爲管理員和crewhome.php爲職工

+3

你假定每個人都有一個獨特的密碼? :) – 2014-11-25 02:10:44

+3

所以你現在*開發一些使用不推薦的'mysql_'函數?個人不想聘請你作爲開發人員。 – 2014-11-25 02:15:32

回答

1
$query=mysql_query("update account set acc_pword='$acc_pword2' where acc_pword='$acc_pword';")or die("JBSOFTWARES 1".mysql_error()); 

此行更新任何和所有帳戶密碼爲$acc_pword。您需要將更新限制爲當前登錄的用戶。

+0

我該怎麼做? – 2014-11-25 02:10:09

+1

@RanierLizada通過添加'AND acc_uname ='$ acc_uname'' ...說,你應該(不,必須)在SQL中正確地轉義你的變量。 – 2014-11-25 02:12:10

+0

它的工作原理。謝謝 – 2014-11-25 02:18:25

0

而不是在WHERE子句中使用密碼本身,我建議使用用戶帳戶。那麼不可能改變錯誤的密碼。

變化:

$query=mysql_query("UPDATE account SET acc_pword='$acc_pword2' 
      WHERE acc_pword='$acc_pword';")or die("JBSOFTWARES 1".mysql_error()); 

要:

$query=mysql_query("UPDATE account SET acc_pword='$acc_pword2' 
      WHERE acc_uname='$acc_uname';")or die("JBSOFTWARES 1".mysql_error()); 
+0

如果你提供了一個正確轉義的例子,我會對此讚不絕口 – 2014-11-25 02:15:15

+0

@JonathanGray你是指一個準備好的查詢嗎? – EternalHour 2014-11-25 03:33:27

0

第一個答案是正確的,並回答你的跟進問題。你只需要瞭解你的查詢條件..

變化

$query=mysql_query("update account set acc_pword='$acc_pword2' where acc_pword='$acc_pword';")or die("JBSOFTWARES 1".mysql_error()); 

$query=mysql_query("update account set acc_pword='$acc_pword2' where user_id = currentUser;")or die("JBSOFTWARES 1".mysql_error()); 
+0

感謝那 – 2014-11-25 02:21:33

+0

請接受我的答案,如果它可以幫助你 – 2014-11-25 02:25:33