Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // If the form was submitted
- if (isset($_POST['username']) && isset($_POST['password']) {
- // Start the session
- session_start();
- // Connect to the database
- $db = new PDO("mysql:host=localhost;dbname=members;port=3306");
- // Encrypt the password - SIMPLE ENCRYPTION
- $pass = md5(sha1($_POST['password']));
- // Check if the user and pass match
- $query = $db->prepare("SELECT COUNT(*) FROM users WHERE username=? AND password=?");
- $query->execute($_POST['username'], $pass);
- // If it does match
- if ($query->fetchColumn() >= 1) {
- // Register session and redirect
- $_SESSION['username'] = $_POST['username'];
- header("location:members.php");
- }else{
- // Echo a message
- die('Username or password is incorrect');
- }
- }else{ ?>
- <html>
- <head>
- <title>Login</title>
- </head>
- <body>
- <form method="post" action="login.php">
- Username: <input type="text" name="username"><br>
- Password: <input type="password" name="password"><br>
- <input type="submit" value="Login">
- </form>
- </body>
- </html>
- <?php } ?>
Add Comment
Please, Sign In to add comment