X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=code%2Fconfig.php;h=d863f7d3f3e3738c7aa9c042fcde09c4e75e2312;hb=db8720bf63328fee760fc2c1d1aebd7844c9f8ce;hp=1e59d64fd25280c49fee9f992716d2fdb0d6c2cc;hpb=a8968f20cd3b06b2cc19de6871019d4aaae6b79b;p=contractor-progress.git diff --git a/code/config.php b/code/config.php index 1e59d64..d863f7d 100644 --- a/code/config.php +++ b/code/config.php @@ -22,5 +22,35 @@ function logged_in_as_contractor() { } function enc_money($float) { - return format_money($float, $cents = true); + return format_money($float, $cents = false); +} + +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; }