A
A
Arthur2016-01-14 19:50:10
PHP
Arthur, 2016-01-14 19:50:10

Md5 encryption and password recovery, what could be wrong?

Greetings, I wrote a password recovery page, everything is sent and entered, only another hash is obtained. For example, when a generated password is entered into md5, the encoder hash is one, but I have the same password in the database with a different hash. Something doesn't add up here.
Here is the code, can someone tell me what I missed:

<?php
if($_SESSION['usern']) { header("Location: $url"); }
?>
<div class="bg-color white rounded event-item">
<div class="box-padding narrow">
<h3>Восстановление пароля</h3>
                
<?php
if(isset($_POST['do_reset'])) {
$email = protect($_POST['email']);
$select_is = mysql_query("SELECT * FROM users WHERE email = '$email'");
                
if(empty($email) ) { echo error("Введите адрес электронной почты."); }
elseif(!isValidEmail($email)) { echo error("Введите корректный email адрес."); }
else {
function gen($leight){
    $x = '';

    $str = "qWertYuiopaSdfgHjklzXcvbNm123456789";

    for($i=0; $i<$leight; $i++){
        $x .= substr($str, mt_rand(0, strlen($str)-1), 1);
    }

    return $x;
}


for ($i =0; $i < 1; $i++)
{
  $mepas = (' ' .gen(10).'<br/>');
}
$mepas_md5 = md5($mepas);
$update_it = mysql_query("UPDATE users SET passwd='$mepas_md5' WHERE email = '$email'");

$mailtext = '<b><div style="text-align:left;font-size: 25px;">★ X-Сайт</div></b>
<br/>
Уважаемый <span style="color: #E77225; text-decoration: none;">'.$email.'</span>, вы заказали восстановление пароля.
<br/>
Так как у нас установлено шифрование паролей, мы не можем показать ваш старый пароль, поэтому специально для вас был сгенерирован новый.<br><br>
Ваш новый пароль - <b><span style="background: #2CADB3; color: #fff; text-decoration: none; padding: 0px 10px 0px 10px;">'.$mepas.'</span></b>
<br><br>
Воспользоваться им вы можете при входе на сайт, с Уважением администрация <a href="http://X-Сайт" style="color: #2CADB3; text-decoration: none;">X-Сайта</a>';
$headers="Content-Type: text/html; charset=utf-8\n";
$headers.="From: почта [email protected]";
mail($email, "Восстановление пароля", $mailtext, $headers); {
echo success("Вам отправлено письмо с паролем."); } 
}
}
?>

<div class="row-fluid">
<div class="span12">
<form role="form" action="" method="POST">
<div class="form-group">
<label>Email адрес регистрации</label>
<input type="text" class="form-control span12" name="email">
</div>
<button type="submit" class="btn btn-primary" name="do_reset">Восстановить</button>
</form>
</div>
</div>
</div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daemon23RUS, 2016-01-14
@arturka_v_10

$mepas = (' ' .gen(10).'<br/>');
There is a space at the beginning of the password and a BR tag at the end. I guess
this is superfluous

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question