-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathidentify.php
58 lines (43 loc) · 1.56 KB
/
identify.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
<?php
session_start();
// 接続
$mysqli = new mysqli('localhost', 'root', 'root', 'User authentication');
//接続状況の確認
if (mysqli_connect_errno()) {
echo "データベース接続失敗" . PHP_EOL;
echo "errno: " . mysqli_connect_errno() . PHP_EOL;
echo "error: " . mysqli_connect_error() . PHP_EOL;
exit();
}
// $username = hash_hmac('sha512', $_GET['username'] , 'secret', false);
// $passward = hash_hmac('sha512', $_GET['passward'] , 'secret', false);
$username = $_POST['username'];
$password = $_POST['password'];
$hashedUsername = hash('sha256', $username);
$hashedPassword = hash('sha256', $password);
// データを認証する
$sql = "SELECT * FROM `User` WHERE `username` LIKE '" .$hashedUsername. "' AND `password` LIKE '" .$hashedPassword. "'";//クエリ
$result = $mysqli->query($sql);
//echo $result -> num_rows;
if (!$result -> num_rows) {
echo '認証に失敗しました。'.mysqli_error();
}else{
echo '認証に成功しました';
// パスワードが正しい場合、セッションを開始
$_SESSION['authenticated'] = true;
$_SESSION['username'] = $username;
// 10秒後にセッションを終了するためにタイマーを設定
$_SESSION['expire_time'] = time() + 10;
// index.htmlにリダイレクト
header('Location: index.php');
exit();
}
if(isset($_POST['back'])) {
header("location: login.html");
}
// 切断
$mysqli->close();
?>
<form action="login.php" method="post">
<input type="submit" name="back" value="ログイン画面に戻る" />
</form>