View sourcecode

The following files exists in this folder. Click to view.

create_account.php

43 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?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($filejson_encode($usersJSON_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($filejson_encode($userfileJSON_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();
    }
?>