Sixtens hemsida Uppgifter Blogg Om

Bankapplikation

Gå till sida

Källkod

bank/

logout.php

transfer.php

index.php

login.php

manage.php

signup.php

change_password.php

modules/

user.php

page.php

session.php

utility.php

users/

hjk.json

sixten2.json

sixten.json

wesweb01/bank/modules/utility.php

1 lines
<?php
# Några funktioner som hjälper till med lite allt möjligt.

function generate_uuid(): string
# Någorlunda modifierad funktion som jag hittade online för att skapa 32 byte långa UUIDs.
{
    
$data random_bytes(16);
    
assert(strlen($data) == 16);

    
$data[6] = chr(ord($data[6]) & 0x0f 0x40);
    
$data[8] = chr(ord($data[8]) & 0x3f 0x80);

    return 
vsprintf('%s%s%s%s%s%s%s%s'str_split(bin2hex($data), 4));
}

function 
hash_password($password$salt): string
# Hashar ett lösenord med hjälp av salt.
{
    return 
hash("sha256"$password $saltfalse);
}

class 
RequestResult
    
# Klass för att förmedla både resultat-boolean och ett meddelande i objektform.
    # Används i alla mina funktioner med prefixen try.
{
    public 
$result# Bool
    
public $message# String
    
public function __construct($result$message)
    {
        
$this->result $result;
        
$this->message $message;
    }
}
?>