<?php
header('Content-Type: text/html; charset=utf-8');
require_once 'connectDB.php'; //подключеник БД
session_start();
if ($_POST) {
$name = strip_tags($_POST['name']);
$pass = strip_tags($_POST['password']);
$stmt = $pdo->prepare("SELECT name, password FROM users WHERE name = :name");
$stmt->execute(array(':name' => $name));
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$hash = $result['password'];
/*
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)){
$passBD=$result['password'];
}*/
if (password_verify($pass, $hash )) {
echo "yes";
$_SESSION["session_username"]=$result['name'];
header('Location: index.php');
exit();
} else {
die('Access denied! <br /> <a href="login.php">to Back</a>');
}
}
else {
die('Access denied! <br /> <a href="login.php">to Back</a>');
}
?>
<!DOCTYPE>
<html>
<head>
<title>Ajax</title>
</head>
<body>
<!-- form start -->
<form method="post" role="form" id="register-form" autocomplete="off" action='handler.php'>
<div class="form-header">
<h3 class="form-title"><i class="fa fa-user"></i><span class="glyphicon glyphicon-user"></span> Sign Up</h3>
<div class="pull-right">
<h3 class="form-title"><span class="glyphicon glyphicon-pencil"></span></h3>
</div>
</div>
<div class="form-body">
<!-- json response will be here -->
<div id="errorDiv"></div>
<!-- json response will be here -->
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div>
<input name="name" type="text" class="form-control" placeholder="Name">
</div>
<span class="help-block" id="error"></span>
</div>
<div class="row">
<div class="form-group col-lg-6">
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></div>
<input name="password" id="password" type="password" class="form-control" placeholder="Password">
</div>
<span class="help-block" id="error"></span>
</div>
</div>
</div>
<div class="form-footer">
<button type="submit" class="btn btn-info" id="btn-signup">
<span class="glyphicon glyphicon-log-in"></span> Sign Me Up !
</button>
</div>
</form>
<div class="alert alert-info">
</div>
</body>
</html>
$name = strip_tags($_POST['name']);
$pass = strip_tags($_POST['password']);
$stmt->execute(array(':name' => $_POST['name']));
$stmt = $pdo->prepare("SELECT name, password FROM users WHERE name = :name");
$hash = $result['password'];