Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once $_SERVER['DOCUMENT_ROOT'].'/api/includes.php';
- function Authenticate($username, $password) {
- $getInfo = $GLOBALS['db']->prepare("SELECT * FROM users WHERE username = :username");
- $getInfo->bindParam(":username", $username, PDO::PARAM_STR);
- $getInfo->execute();
- $dbcheck = $getInfo->fetch(PDO::FETCH_ASSOC);
- if(password_verify($password, $dbcheck['password'])) {
- $_SESSION['loggedin'] = true;
- } else {
- $invalidlogin = true;
- }
- }
- function Signup($username, $password, $passwordconfirm) {
- $exists = $GLOBALS['db']->prepare("SELECT * FROM users WHERE username = :username");
- $exists->bindParam(":username", $username, PDO::PARAM_STR);
- $exists->execute();
- if($exists->rowCount() < 1) {
- if($password == $passwordconfirm) {
- $hashedpw = password_hash($password, PASSWORD_DEFAULT);
- $accountCreation = $GLOBALS['db']->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
- $accountCreation->bindParam(":username", $username, PDO::PARAM_STR);
- $accountCreation->bindParam(":password", $hashedpw, PDO::PARAM_STR);
- $accountCreation->execute();
- echo '
- <div class="alert alert-success" role="alert">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <strong>Well done!</strong> Your account was created.
- </div>';
- } else {
- $error = "Your password confirmation does not match the password you inputted.";
- echo '
- <div class="alert alert-danger" role="alert">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <strong>Uh oh...</strong> Your password confirmation didn\'t match your password!
- </div>';
- }
- } else {
- $error = "There is already a user with that username";
- echo '
- <div class="alert alert-danger" role="alert">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <strong>Uh oh...</strong> There is already a user named ' . $username . '!
- </div>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement