Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pdo = new PDO("mysql:host=localhost;dbname=database", 'username', 'password');
- if(isset($_POST['formreg'])) {
- $username = $_POST['user_input'];
- $password = $_POST['pass_input'];
- $query = $pdo->prepare("INSERT INTO users (user,pass) VALUES (:user_token,:pass_token)");
- $values = array(
- "user_token" => $username,
- "pass_token" => sha1($password)
- );
- $query->execute($values);
- }
- if(isset($_POST['formlog'])) {
- $username = $_POST['user_input'];
- $password = $_POST['pass_input'];
- $query = $pdo->prepare("SELECT * FROM users WHERE user=:user_token LIMIT 1");
- $values = array(
- "user_token" => $username
- );
- $query->execute($values);
- $row = $query->fetch(PDO::FETCH_ASSOC);
- if($row !== false) {
- if($row["pass"] === sha1($password)) {
- echo "Login success.";
- } else {
- echo "Wrong password.";
- }
- } else {
- echo "Username doesn't exist.";
- }
- }
- ?>
- <h1>Login</h1>
- <form action="index.php" method="post">
- username: <input type="text" name="user_input"><br>
- password: <input type="password" name="pass_input"><br>
- <input type="hidden" name="formlog" value="1">
- <input type="submit">
- </form>
- <h1>Register</h1>
- <form action="index.php" method="post">
- username: <input type="text" name="user_input"><br>
- password: <input type="password" name="pass_input"><br>
- <input type="hidden" name="formreg" value="1">
- <input type="submit">
- </form>
Add Comment
Please, Sign In to add comment