X-Git-Url: https://jasonwoof.com/gitweb/?p=contractor-progress.git;a=blobdiff_plain;f=code%2Fconfig.php;h=32d8076e4f8249e718ac98f5d9269b0d0da8511e;hp=1e59d64fd25280c49fee9f992716d2fdb0d6c2cc;hb=b928153ea8d0fa60bc6f7632a81b77609e243014;hpb=535cdc5a3f32063d12d29b99cffeae9d39ae8ef5 diff --git a/code/config.php b/code/config.php index 1e59d64..32d8076 100644 --- a/code/config.php +++ b/code/config.php @@ -24,3 +24,33 @@ function logged_in_as_contractor() { function enc_money($float) { return format_money($float, $cents = true); } + +function logged_in() { + return session_exists_and_authed(); +} + +# 1st arg: the correct encrypted password +# 2nd arg: clear-text password entered by someone +function check_password($encrypted, $pass) { + if(strpos($encrypted, ':') !== 32) { + die("password field corrupted"); + } + + list($md5, $salt) = explode(':', $encrypted); + + if(md5($salt . $pass) == $md5) { + return true; + } + + return false; +} + +function encrypt_password($plain) { + $password = ''; + + $salt = substr(md5(rand() . "f"), 0, 2); # FIXME make this more effecient and clear + + $password = md5($salt . $plain) . ':' . $salt; + + return $password; +}