Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include ("myConn.php");
- session_start();
- if(isset($_POST['submit'])){
- $error = '';
- //username and password sent from Form, and trimmed for whitespace
- $uname = trim($_POST['username']);
- $pwd = trim($_POST['password']);
- if($uname == '')
- $error .= '<b>Username:</b> Please enter a Username<br>';
- if($pwd == '')
- $error .= '<b>Password</b> Please enter a Password<br>';
- if($error == ''){
- $query = $db->prepare('SELECT id,username,password FROM students WHERE username = :username');
- $query->bindParam(':username', $uname);
- $query->execute();
- $result = $query->fetch(PDO::FETCH_ASSOC);
- if($result === false){
- $error .= '<b>Username</b> or <b>Password</b> are not found<br>';
- } else {
- $validpwd = password_verify($pwd, $result['password']);
- if($validpwd){
- $_SESSION['user_id'] = $result['id'];
- header('location: homepage.php');
- exit;
- }
- }
- /*if($result->num_rows > 0 && password_verify($pwd, $result['password'])){
- $_SESSION['username'] = $result['username'];
- header('location: homepage.php');
- exit;
- } else {
- $error .= '<b>Username</b> or <b>Password</b> are not found<br>';
- }*/
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="style.css" />
- <form action="index.php">
- <button type="submit" class="logbutton" value="back">Go Back</button>
- </form>
- <div class="logintitle">
- <h1>Login</h1>
- </div>
- </head>
- <br><br>
- <body>
- <div class= "page">
- <div class="regbox">
- <br>
- <form action="" method="post">
- <label for 'username'>Username: </label>
- <input type="text" id="username" name="username" maxlength="20" placeholder="Client1" pattern="^(?=.*[A-Za-z])[A-Za-z\d]{4,}$" title="Four characters or numerics + no special characters" autofocus required />
- <br><br>
- <label for 'password'>Password: </label>
- <input type="password" id="password" name="password" maxlength="20" pattern="^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$" title="Contain six characters + one numeric" required />
- <br><br><br>
- <button type="submit" class="logbutton" value="submit" name="submit">Submit</button>
- <br><br>
- </form>
- </div>
- <br><br>
- <div class="errorbox">
- <?php
- if(isset($error)){
- echo ''.$error.'';
- }
- ?>
- </div>
- </div>
- </body>
- <footer>
- </footer>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement