şifresini değiştirmek

4 Cevap

I've created a code to change a password. Now it seem contain an error. When I fill in the form to change password, and click save the error message:

Sen kimliği girin unuttunuz!

Lütfen tekrar deneyin.

Gerçekten hata mesajı ne anlama bilmiyorum. Çocuklar memnun. Bana bunu düzeltmek yardımcı.

İşte kod mi:

<?php # change password.php

//set the page title and include the html header.
$page_title = 'Change Your Password';
//include('templates/header.inc');

if(isset($_POST['submit'])){//handle the form
 require_once('connectioncomplaint.php');//connect to the db.
 //include "connectioncomplaint.php";

 //create a function for escaping the data.
 function escape_data($data){
  global $dbc;//need the connection.
  if(ini_get('magic_quotes_gpc')){
   $data=stripslashes($data);
  }
  return mysql_real_escape_string($data);
 }//end function

 $message=NULL;//create the empty new variable.

 //check for a username
 if(empty($_POST['userid'])){
  $u=FALSE;
  $message .='<p> Sen kimliği girin unuttunuz!</p>';
 }else{
  $u=escape_data($_POST['userid']);
 }

 //check for existing password
 if(empty($_POST['password'])){
  $p=FALSE;
  $message .='<p>You forgot to enter your existing password!</p>';
 }else{
  $p=escape_data($_POST['password']);
 }

 //check for a password and match againts the comfirmed password.
 if(empty($_POST['password1'])) {
  $np=FALSE;
  $message .='<p> you forgot to enter your new password!</p>';
 }else{
  if($_POST['password1'] == $_POST['password2']){
  $np=escape_data($_POST['password1']);
 }else{
  $np=FALSE;
  $message .='<p> your new password did not match the confirmed new password!</p>';
 }
}

if($u && $p && $np){//if everything's ok.

 $query="SELECT userid FROM access WHERE (userid='$u' AND password=PASSWORD('$p'))";
 $result=@mysql_query($query);
 $num=mysql_num_rows($result);
 if($num == 1){
  $row=mysql_fetch_array($result, MYSQL_NUM);

  //make the query
  $query="UPDATE access SET password=PASSWORD('$np') WHERE userid=$row[0]";
  $result=@mysql_query($query);//run the query.
  if(mysql_affected_rows() == 1) {//if it run ok.

   //send an email,if desired.
   echo '<p><b>your password has been changed.</b></p>';
   //include('templates/footer.inc');//include the HTML footer.
   exit();//quit the script.

  }else{//if it did not run OK.
   $message= '<p>Your password could not be change due to a system error.We apolpgize for any inconvenience.</p><p>' .mysql_error() .'</p>';
   }
  }else{
   $message= '<p> Your username and password do not match our records.</p>';
  }
  mysql_close();//close the database connection.

 }else{
  $message .='<p>Lütfen tekrar deneyin.</p>';
 }
}//end of the submit conditional.

//print the error message if there is one.
if(isset($message)){
 echo'<font color="red">' , $message, '</font>';
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

4 Cevap

Veritabanında gerçek şifre saklamak etmeyiniz. Şifre karma oluşturun ve saklayın. , Bir kullanıcı oturum açtığında, gelen şifreyi karma ve kullanıcı için karma şifresini eşleşirse kontrol ettiğinizde. http://phpsec.org/articles/2005/password-hashing.html daha fazla bilgi için bkz.

Ayrıca, bu oturumda kimliği saklamak ve oldukça formda onu almak daha oradan almak daha güvenli olacaktır. Giriş sayfası gizli bile, ikame edilebilir bir takım yollardan vardır. Bu bir kullanıcının başka bir kullanıcının kimliği ve şifresini bilen varsa, onlar bir saptanamayan şekilde değiştirebilirsiniz, uygulamada küçük bir delik bırakır. Bu şifre formu (veya url) gelen kullanıcı kimliği almak bile oturum olan bu kullanıcı kaydı yok olmasına rağmen değişmiş olabilir, olduğunu, her zaman üzerinde faaliyet verileri kendi olup olmadığını kontrol edin Tabii, bunlar yeterli ayrıcalıklara sahip bir kullanıcı, olmadıkça, başkası değil bu.

Bu sizin POST parametreleri ile userid birlikte göndermek olmadığı anlamına gelir. Muhtemelen, form adı ile bir unsur içermiyordu userid. Hata bu hattan geliyor:

if(empty($_POST['userid'])){

Bu hata nedeniyle, bu testin görüntülenir:

 if(empty($_POST['userid'])){
  $u=FALSE;
  $message .='<p> You forgot enter your userid!</p>';
 }

Hangi sunucu formundan a userid alanını almaz anlamına gelir.


I'm guessing you should make sure there is such a field in your form -- and it'll have to contain the userid of the user for which you want to change the password.

Muhtemelen olsa, bir hidden girişini kullanmak gerekir, bu alan görüntülenmesini istemiyorum göz önüne alındığında:

<input type="hidden" name="userid" 
    value="<?php echo htmlspecialchars(HERE THE USERID); ?>" />

Koduna göre o userid POST değişkeni boş olduğu anlamına gelir. Eğer bunun için kullandığımız alanın adını doğrulayın.