Hej, zaprojektowałem proste logowanie 2-etapowe (na maila przychodzi kod do logowania po wpisaniu hasła).
Logowanie to jest używane tylko przez 2 osoby ale do bardzo wrażliwych danych więc mam następujące pytanie: czy jest bezpieczne? Może popełniłem jakiś błąd który może powodować "włam"? Dzięki z góry za odpowiedź (IMG:
style_emoticons/default/smile.gif)
login.php
<?php
require 'dbsoft.php';
$password = $_POST['password'];
$email = htmlentities($_POST['email'], ENT_QUOTES
, "UTF-8");
$sekret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$sprawdz = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$sekret.'&response='.$_POST['g-recaptcha-response']);
$odpowiedz = json_decode($sprawdz);
if ($odpowiedz->success==false)
{
$_SESSION['e_bot']="Potwierdź, że nie jesteś botem!";
header('Location: ../login.php'); }
$sql = 'SELECT * FROM account WHERE email=?';
$statement = $connection->prepare($sql);
$statement->execute([$email]);
$oz = $statement->rowCount();
if($oz>0){
$row = $statement->fetchAll(PDO::FETCH_OBJ);
foreach($row as $rows):
$password_base = $rows->password;
$email = $rows->email;
$id_base = $rows->id;
endforeach;
if (password_verify($password, $password_base))
{
$_SESSION['verify'] = true;
$_SESSION['id_session'] = $id_base;
function random(int $i)
{
}
$code = random(35);
$time = date("Y-m-d H:i:s");
$sql = "INSERT INTO verify_code (id_user, code, date, status_code) VALUES (?, ?, ?, ?)";
$connection->prepare($sql)->execute([$id_base, $code, $now, 0]);
$message="Kod do weryfikacji:\n\n$code\n\nWiadomosc zostala wygenerowana automatycznie: $time";
$sender="From: domena.pl";
@mail($email, "Kod weryfikacyjny", $message, $sender);
unset($_SESSION['error']);
$statement = null;
$connection = null;
header('Location: verify.php');
}
else
{
$_SESSION['error'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
$statement = null;
$connection = null;
header('Location: ../login.php');
}
} else {
$_SESSION['error'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>';
$statement = null;
$connection = null;
header('Location: ../login.php');
}
$statement = null;
$connection = null;
?>
verify_check.php:
<?php
if (!isset($_SESSION['verify'])) {
header('Location: ../login.php'); }
if(empty($_POST["code"]) || !isset($_POST["code"])){
$_SESSION['error'] = '<span style="color:red">Nie podano kodu</span>';
header('Location: verify.php');
}
require '../database_connect/dbsoft.php';
$sql = 'SELECT * FROM verify_code WHERE code=?';
$statement = $connection->prepare($sql);
$statement->execute([$code]);
$row = $statement->fetchAll(PDO::FETCH_OBJ);
foreach($row as $rows):
$id_user = $rows->id_user;
$date = $rows->date;
$code_base = $rows->code;
$status_base = $rows->status_code;
$ide = $rows->id;
endforeach;
if($status_base == 0){
if($code_base == $code){
if($_SESSION['id_session'] == $id_user){
if($now <= $date){
$_SESSION['admin'] = true;
$st = 1;
$sql = "UPDATE verify_code SET status_code=? WHERE id=?";
$statement = $connection->prepare($sql);
$statement->execute([$st, $ide]);
unset($_SESSION['verify']);
$statement = null;
$connection = null;
}else{
}
}else{
}
}else{
echo 'Nieprawidłowy kod'; }
}else{
echo 'Kod został zużyty'; }
Jeśli jest dobrze to proszę też o odpowiedź (IMG:
style_emoticons/default/smile.gif)
Ten post edytował gloweres 9.11.2020, 03:00:50