Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
206cde/register.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (44 sloc)
1.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
$servername = "localhost"; | |
$server_username = "root"; | |
$server_password = ""; | |
$dbName = "ar"; | |
try{ | |
$conn = new PDO('mysql:host=localhost;dbname=ar;','root',''); | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); | |
$username = ($_POST['username']); | |
$password = ($_POST['pw']); | |
$name = ($_POST['name']); | |
$cardID = ($_POST['cardID']); | |
//strength of encryption | |
$options = [ | |
'cost' => 12, | |
]; | |
$passwordNew = password_hash($password, PASSWORD_BCRYPT,$options); | |
// check if the username does not exist in database | |
$stmt = $conn->prepare('SELECT * FROM accounts WHERE username = :username'); | |
$stmt->bindParam(':username',$username); | |
$stmt->execute(); | |
$row = $stmt->fetch(PDO::FETCH_ASSOC); | |
// If does not exist - create it (account) | |
if(!$row){ | |
if($stmt = $conn->prepare('INSERT INTO accounts (username, pw, name, cardID) VALUES (:username, :pw, :name, :cardID)')){ | |
$stmt->bindValue(':username',$username, PDO::PARAM_STR); | |
$stmt->bindValue(':pw',$passwordNew, PDO::PARAM_STR); | |
$stmt->bindValue(':name',$name, PDO::PARAM_STR); | |
$stmt->bindValue(':cardID',$cardID, PDO::PARAM_INT); | |
$stmt->execute(); | |
echo "0"; | |
} | |
} | |
else{ | |
// tells unity if the account exists | |
die('Account Exists!'); | |
//echo"00"; | |
} | |
} catch(PDOException $pe){ | |
die("Could not connect" . $pe->getMessage()); | |
} | |
?> |