I've been tasked with creating a system to this, the issue is I can’t store anything in a database as the server is set up ridiculously badly and basically any database related storage is unavailable for use.
So I came to the conclusion of storing any and all data in a json format. Now my issue is I need to store user credentials as access is only allowed to authorised users.
How would I go about storing these user credentials? Would I store them with one-way password hashes or should I use something like mcrypt_encrypt() & mcrypt_decrypt() respectively?
Encryption Function
function encrypt($string) {
if (extension_loaded('mcrypt')) {
return trim($this->base64_url_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key, $string, MCRYPT_MODE_ECB)));
} else {
return false;
}
}
Decryption Function
function decrypt($string) {
if (extension_loaded('mcrypt')) {
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->key, $this->base64_url_decode($string), MCRYPT_MODE_ECB));
} else {
return false;
}
}
And the following two base64 functions from here:
function base64_url_encode($input) {
return strtr(base64_encode($input), '+/=', '-_,');
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_,', '+/='));
}