finished login stg 1

This commit is contained in:
2018-05-10 09:27:21 -04:00
parent ca630dda67
commit 4bc9c83e38
14 changed files with 2900 additions and 84 deletions

View File

@@ -1,38 +1,62 @@
<?php
/* development only */
header("Access-Control-Allow-Origin: *");
require '../vendor/autoload.php';
require 'dbConfig.php';
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
$passwordSalt = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824";
if(isset($_GET['login'])) {
$userName = $_POST['userName'];
$password = $_POST['password'];
$userName = $_GET['userName'];
$password = $_GET['password'];
$hashedPassword = crypt( $password, $passwordSalt );
$hashedPassword = crypt( $password, $passwordSalt );
$stmt = $connect->prepare('SELECT userId, password FROM users WHERE userName = :userName');
$stmt->execute(array(
':userName' => $userName
));
$stmt = $connect->prepare('SELECT * FROM users WHERE userName = :userName');
$stmt->execute(array(
':userName' => $userName
));
$data = $stmt->fetch(PDO::FETCH_ASSOC);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
if($data == false){
//$errMsg = "User $username not found.";
echo(0);
}else {
if( hash_equals($hashedPassword,$data['password'] ) ) {
echo("valid");
exit;
}else{
echo("d");
echo($hashedPassword . "<br />" . $data['password'] );
}
if( $data == false ){
http_response_code(400);
die();
}else {
if( hash_equals($hashedPassword,$data['password'] ) ) {
if( $data['userName'] == "ckoch" ){
$signer = new Sha256();
$token = (new Builder())
->setIssuer("http://pugludos.com")
->setIssuedAt(time())
->set("userName", $data['userId'])
->sign($signer, "testing")
->getToken();
$userData = array();
$userDatap["id"] = $data['userId'];
$userDatap["username"] = $data['userName'];
$userDatap["firstName"] = $data['firstName'];
$userDatap["lastName"] = $data['lastName'];
$userDatap["email"] = $data['email'];
$userDatap["token"] = (string)$token;
echo( json_encode( $userDatap ) );
die();
}else{
http_response_code(400);
die();
}
}else{
http_response_code(400);
die();
}
}
?>
?>