123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- /*
- * Message manager
- * Types of notifications:
- * success
- * fail
- * info
- */
- $MESSAGES = array();
- function add_message($type, $message){
- global $MESSAGES;
- $newmessage = array();
- $newmessage['type'] = $type;
- $newmessage['message'] = $message;
- $MESSAGES[] = $newmessage;
- }
- function output_messages(){
- echo "<div class=\"messages\">";
- global $MESSAGES;
- foreach($MESSAGES as $message){
- echo "<div class=\"notification notification-".$message['type']."\">".$message['message']."</div>";
- }
- echo "</div>";
- }
- /*
- * Function checks password input for new password
- * Return codes:
- * true: password is okay
- * 2: One password field is empty
- * 3: Passwords are not equal
- * 4: Passwort is too snort
- */
- function check_new_pass($pass1, $pass2){
- global $PASS_ERR;
- global $PASS_ERR_MSG;
- // Check if one passwort input is empty
- if($pass1 !== "" && $pass2 !== ""){
- // Check if password are equal
- if($pass1 === $pass2){
- // Check if password length is okay
- if(strlen($pass1) >= MIN_PASS_LENGTH){
- // Password is okay.
- return true;
- }
- else{
- // Password is not long enough
- $PASS_ERR = 4;
- $PASS_ERR_MSG = "Password is not long enough. Please enter a password which has ".MIN_PASS_LENGTH." characters or more.";
- return $PASS_ERR;
- }
- }
- else{
- // Passwords are not equal
- $PASS_ERR = 3;
- $PASS_ERR_MSG = "Passwords are not equal.";
- return $PASS_ERR;
- }
- }
- else{
- // One password is empty.
- $PASS_ERR = 2;
- $PASS_ERR_MSG = "Not all password fields were filled out";
- return $PASS_ERR;
- }
- }
- function get_hash()
- {
- switch(PASS_HASH_SCHEMA)
- {
- case "SHA-512":
- return '$6$rounds=5000$';
- break;
-
- case "SHA-256":
- return '$5$rounds=5000$';
- break;
-
- case "BLOWFISH":
- return '$2a$09$';
- break;
- }
- }
- function gen_pass_hash($pass){
- $salt = base64_encode(rand(1,1000000) + microtime());
- $hash_schema = get_hash();
- $pass_hash = crypt($pass, $hash_schema.$salt.'$');
- return $pass_hash;
- }
- function write_pass_hash_to_db($pass_hash, $uid){
- global $db;
- $uid = $db->escape_string($uid);
- $pass_hash = $db->escape_string($pass_hash);
- $db->query("UPDATE `".DBT_USERS."` SET `".DBC_USERS_PASSWORD."` = '$pass_hash' WHERE `".DBC_USERS_ID."` = '$uid';");
- }
- /*
- * Add message to logfile
- */
- function writeLog($text){
- if(defined('WRITE_LOG') && defined('WRITE_LOG_PATH')){
- $logdestination = realpath(WRITE_LOG_PATH).DIRECTORY_SEPARATOR."webmum.log";
- if(is_writable(WRITE_LOG_PATH)){
- $logfile = fopen($logdestination, "a") or die("Unable to create or open logfile \"".$logdestination."\" in root directory!");
- fwrite($logfile, date('M d H:i:s').": ".$text."\n");
- fclose($logfile);
- }
- else{
- die("Directory \"".WRITE_LOG_PATH."\" is not writable");
- }
- }
- }
- ?>
|