/
findpw.php
50 lines (40 loc) · 1.18 KB
/
findpw.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?
function Hashed($ip_pass, $salt)
{
$arr = array();
$arr[0] = $ip_pass;
$arr[1] = $salt;
$hashedPW = implode($arr);
$hashedPW = md5($hashedPW);
//echo($hashedPW);
return $hashedPW;
}
$connect=mysqli_connect("localhost", "root", "apmsetup", "Task");
if (mysqli_connect_errno()) {
die('Connect Error: '.mysqli_connect_error());
}
$sql = "select * from student_list where Mail='$mail'";
$result = mysqli_query($connect,$sql);
$num_match=mysqli_num_rows($result); //넘버 받아오기
if(!$num_match)
{
echo("
<script>
window.alert('등록되지 않은 아이디입니다.')
history.go(-1)
</script>
");
}
else
{
$tmpPW = mt_rand(1000, 9999);
$salt = mt_rand(1000, 9999);
$tmphashedPW = Hashed($tmpPW, $salt);
$sql = "UPDATE student_list SET HashedPW = '$tmphashedPW' where Mail = '$mail'";
mysqli_query($connect,$sql);
$sql = "UPDATE student_list SET Salt = '$salt' where Mail = '$mail'";
mysqli_query($connect,$sql);
mysqli_close($connect); // DB 연결 끊기
echo('New PW is '.$tmpPW);
}
?>