-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
84 lines (73 loc) · 2.06 KB
/
login.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Contents-Type" conten="text/html;charset=UTF-8">
<title> Login </title>
</head>
<body>
<center>
<font size='10'> login<br><br> </font>
<form method="post" action="">
<table>
<tbody>
<tr>
<th> User   Name</th>
<th> <input type="text" name="username"> </th>
</tr>
<tr>
<th> Password</th>
<th> <input type="password" name="password"> </th>
</tr>
<tr>
<th colspan=2> <input type="submit" name="login" value="login"> </th>
</tr>
</tbody>
</table>
</center>
</body>
</html>
<?php
$dbname = "User";
$index_POST = array( 0 => "username", 1 => "password", );
$index_AUTH = array( 0 => "id",
1 => "name",
2 => "password", );
echo "<center>";
if( $_POST["login"] != "login" )
die( "" );
for( $i = 0; $i < 2; $i++ ){
if( !$_POST[$index_POST[$i]] )
die( "<br>require ".$index_POST[$i] );
}
session_start();
$link = mysql_connect( "localhost", "team2", "testpassjhkkrokw" );
if( !$link )
die( "Connection Failed.".mysql_error() );
$dbselect = mysql_select_db( $dbname, $link );
if( !$dbselect )
die( "DB Select Failed.".mysql_error() );
$chartype = mysql_query( "SET NAMES utf8", $link );
if( !$chartype )
die( "Query Failed.".mysql_error() );
$query = "SELECT * from ".$dbname.".Auth where name = '".$_POST["username"]."';";
$result = mysql_query( $query );
if( !$result )
die( "Query Failed.".mysql_error() );
if( !( $data = mysql_fetch_assoc( $result ) ) ){
mysql_close( $link );
die( "You don't sign up." );
} else{
$flag = mysql_close( $link );
if( !$flag )
die( "Close Failed.".mysql_error() );
if( password_verify( $_POST["password"], $data["password"] ) ){
session_regenerate_id( true );
$_SESSION["id"] = $data["id"];
header( "Location: userdata.php");
exit;
} else{
die( "Authentication Failed." );
}
}
echo "</center>";
?>