このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
076server/app/Http/Controllers/User/Login.php

58 行
2.0 KiB
PHP
Raw 通常表示 履歴

2020-10-06 11:22:46 +09:00
<?php
namespace App\Http\Controllers\User;
2021-08-17 18:17:36 +09:00
use Illuminate\Support\Facades\DB;
2020-10-06 11:22:46 +09:00
use Illuminate\Http\Request;
// use Illuminate\Support\Facades\Log;
class Login {
public function index (Request $r) {
if (isset($_COOKIE['kero_token'])) return redirect('');
$res = array();
$err = '';
if (isset($r->username) && isset($r->password)) {
$res = $this->login($r);
2020-10-06 11:22:46 +09:00
if (isset($res['kero_token'])) return redirect('');
$err = $res['err'];
}
return view('pages.site.login', ['res' => $res, 'err' => $err]);
}
public function login (Request $r) {
$banned = DB::table('blg_blacklist')->get();
foreach ($banned as $b) {
$ip = explode('.', getIp());
$ban = explode('.', $b->ipaddress);
if (
($ban[0] == $ip[0] && $ban[1] == $ip[1] && $ban[2] == $ip[2] && $ban[3] == $ip[3]) ||
($ban[0] == $ip[0] && $ban[1] == $ip[1] && $ban[2] == $ip[2] && $ban[3] == '*') ||
($ban[0] == $ip[0] && $ban[1] == $ip[1] && $ban[2] == '*' && $ban[3] == '*')
2021-09-29 16:36:35 +09:00
) return redirect('/');
}
if (!empty($r)) {
$checkName = DB::table('users')->where('username', $r->username)->first();
if ($checkName) {
// $checkName = json_decode(json_encode($checkName), true);
$checkPass = hash('sha256', $r->password . $checkName->salt);
for ($round = 0; $round < 65536; $round++) $checkPass = hash('sha256', $checkPass . $checkName->salt);
if (hash_equals($checkPass, $checkName->password)) {
if (!$checkName->kero_token) {
$checkName->kero_token = makeToken();
DB::table('users')->where('id', $checkName->id)->update(['kero_token' => $checkName->kero_token]);
}
setcookie('kero_token', $checkName->kero_token, time()+157788000, '/', $_SERVER['HTTP_HOST'], 0, 1);
return array('uid' => $checkName->id, 'kero_token' => $checkName->kero_token);
}
}
return array('err' => 'ユーザ名又はパスワードを間違いました。');
}
return array('err' => 'フォームは空です。');
2020-10-06 11:22:46 +09:00
}
}