The following files exists in this folder. Click to view.
create_account.php43 lines UTF-8 Unix (LF)
<?php
$file_in = "accounts/users.json";
$users = json_decode(file_get_contents($file_in), true);
include('functions.php');
if(isset($_POST['username']) and isset($_POST['password'])){
foreach ($users['users'] as $a){ #Loopar igenom users.json för att kolla ifall användaren existerar
if(sha1("LBM".$_POST['password']."Banking") == $a['password'] and $_POST['username'] == $a['user'] and $a['active']){
header('location: index.php?action=login&mess=exists');
exit();
}
$id = $a['userid'];
}
$hash_pass = sha1("LBM".$_POST['password']."Banking"); //krypterar
$id = $id+1;
//Lägger in information om användaren i users.json
$users['users'][] = ['user'=> $_POST['username'], 'password'=> $hash_pass, 'userlvl'=> 'user', 'userid'=> $id, 'active'=> True];
$file = fopen($file_in, "w");
fwrite($file, json_encode($users, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
fclose($file);
//Skapar användarens personliga fil
$new_file = "accounts/".$_POST['username'].$id.".json";
$file = fopen($new_file, "w");
fclose($file);
//Lägger till information i användarens personliga fil
$file_in = "accounts/".$_POST['username'] . $id.".json";
$userfile = json_decode(file_get_contents($file_in), true);
$userfile['accounts'][] = ['name'=> 'Personal account', 'accountid'=> 1, 'active'=> True, 'transactions'=> []];
$file = fopen($file_in, "w");
fwrite($file, json_encode($userfile, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
fclose($file);
//Ger användaren 1000 pengar
add($_POST['username'] . $id, 'Personal account', 'deposit', 1000);
header('location: index.php?action=login&mess=created');
exit();
}
else{
header('location: index.php?action=login&mess=error');
exit();
}
?>