Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('sql.php');
- $username = $_POST['username'];
- $password = $_POST['password'];
- $confirm = $_POST['confirm'];
- if($username=='' || $password=''){header('Location:/register.php');}
- if($password!=$confirm){header('Location:/register.php');}
- $sql = "INSERT INTO login (username, password) VALUES ('".$username."', '".password_hash($password, PASSWORD_DEFAULT)."')";
- if (mysqli_query($mysqli, $sql)) {
- header('Location: /dashboard.php');
- } else {
- echo $mysqli->error;
- }
- mysqli_close($mysqli);
- <?php
- session_start();
- $error='';
- if (isset($_POST['submit'])) {
- if (empty($_POST['username']) || empty($_POST['password'])) {
- header("Location: /admin.php?error=invalid");
- } else {
- include('sql.php');
- $username = mysqli_real_escape_string($mysqli,stripslashes($_POST['username']));
- $password = mysqli_real_escape_string($mysqli,stripslashes($_POST['password']));
- $sql="SELECT * FROM login WHERE username='".$username."'";
- $result=$mysqli->query($sql);
- if ($result->num_rows == 1) {
- while($row = $result->fetch_assoc()) {
- $verify = password_verify($password, $row['password']);
- if($verify==false){
- header("Location: /admin.php?error=mismatch");
- } else {
- $_SESSION['login_user']=$username;
- $_SESSION['login_pass']=$password;
- if($_POST['stay']=='stay'){
- setcookie('username', $username, time()+31536000, '/');
- setcookie('password', $password, time()+31536000, '/');
- }
- header("location: /dashboard.php");
- }
- }
- } else {
- header("Location: /admin.php?error=mismatch");
- }
- mysqli_close($mysqli);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement