added login
This commit is contained in:
34
app/scripts/functions.php
Normal file
34
app/scripts/functions.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
include("database_queries.php");
|
||||
|
||||
function check_login($con) {
|
||||
|
||||
if(isset($_SESSION['user_id'])) {
|
||||
|
||||
$id = $_SESSION['user_id'];
|
||||
if(check_user_id($con, $id)) {
|
||||
return get_user_data_id($con, $id);
|
||||
} else {
|
||||
header("Location: login.php");
|
||||
die;
|
||||
}
|
||||
} else {
|
||||
header("Location: login.php");
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
function generate_salt() {
|
||||
return substr(bin2hex(random_bytes(128)), 0, 128);
|
||||
}
|
||||
|
||||
function generate_user_id($username, $salt) {
|
||||
$uname = $username . $salt;
|
||||
return hash('sha3-512', $uname);
|
||||
}
|
||||
|
||||
function generate_password_hash($password, $salt) {
|
||||
$pword = $password . $salt;
|
||||
return hash('sha3-512', $pword);
|
||||
}
|
||||
Reference in New Issue
Block a user