Skip to content

Instantly share code, notes, and snippets.

@hasinhayder
Last active November 30, 2023 05:15
Show Gist options
  • Save hasinhayder/0b095766f7cc95b2d136b2ba6454df30 to your computer and use it in GitHub Desktop.
Save hasinhayder/0b095766f7cc95b2d136b2ba6454df30 to your computer and use it in GitHub Desktop.
mock login
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$users = [
[
'email'=>'[email protected]',
'name'=>'Admin',
'password'=>'admin',
'role'=>'admin',
'token'=>hash('sha256', 'admin')
],
[
'email'=>'[email protected]',
'name'=>'John Doe',
'password'=>'john',
'role'=>'editor',
'token'=>hash('sha256', 'john')
],
[
'email'=>'[email protected]',
'name'=>'Jane Doe',
'password'=>'jane',
'role'=>'editor',
'token'=>hash('sha256', 'jane')
]
];
if(isset($_POST['email']) && isset($_POST['password'])){
$email = $_POST['email'];
$password = $_POST['password'];
foreach($users as $user){
if($user['email'] === $email && $user['password'] === $password){
echo json_encode([
'success'=>1,
'name'=>$user['name'],
'username'=>$user['email'],
'role'=>$user['role'],
'token'=>$user['token']
]);
exit;
}
}
}
echo json_encode([
'success'=>0,
'error'=>'Invalid credentials'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment