-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
66 lines (46 loc) · 2 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
<?php
include("./sql_info.php");
session_start();
if(isset($_POST["user_id"]) && isset($_POST["password"])){
$user_id = $_POST["user_id"];
$password = $_POST["password"];
if(!preg_match("/^[0-9A-Za-z]+$/", $user_id)){
echo("<html><head><meta http-equiv='refresh' content='3;URL=./signup_form.php' /></head>");
echo("<span style='color:#ff0000;'>You can't include mark in User ID.</span><br>");
echo("Redirect to the login page 3 seconds later....</html>");
exit();
}
try{
$dbh = new PDO($dsn, $sql_user, $sql_password);
$result = $dbh->query("select password from users where id='".$user_id."';");
foreach($result as $row){
if(password_verify($password,$row["password"])){
$_SESSION['id'] = $user_id;
//dashboardにリダイレクト
echo("<html><head><meta http-equiv='refresh' content='0;URL=./dash.php' /></head><body>Redirect to the dashboard.</body></html>");
exit();
}
}
}catch (PDOException $e){
print('Error:'.$e->getMessage());
die();
}
$accounts = file("./account.csv");
foreach($accounts as $line){
$data = explode(',',$line);
//パスワードidが同じなら
if($data[0] === $user_id){
if(password_verify($password,str_replace("\n","",$data[1]))){
$_SESSION['id'] = $user_id;
//dashboardにリダイレクト
echo("<html><head><meta http-equiv='refresh' content='0;URL=./dash.php' /></head><body>Redirect to the dashboard.</body></html>");
exit();
}
}
}
echo("<html><head><meta http-equiv='refresh' content='3;URL=./login_form.php' /></head>");
echo("<span style='color:#ff0000;'>Login Error.</span><br>");
echo("Redirect to the login page 3 seconds later....</html>");
exit();
}
?>