global.inc.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /*
  3. * Message manager
  4. * Types of notifications:
  5. * success
  6. * fail
  7. * info
  8. */
  9. $MESSAGES = array();
  10. function add_message($type, $message){
  11. global $MESSAGES;
  12. $newmessage = array();
  13. $newmessage['type'] = $type;
  14. $newmessage['message'] = $message;
  15. $MESSAGES[] = $newmessage;
  16. }
  17. function output_messages(){
  18. echo "<div class=\"messages\">";
  19. global $MESSAGES;
  20. foreach($MESSAGES as $message){
  21. echo "<div class=\"notification notification-".$message['type']."\">".$message['message']."</div>";
  22. }
  23. echo "</div>";
  24. }
  25. /*
  26. * Function checks password input for new password
  27. * Return codes:
  28. * true: password is okay
  29. * 2: One password field is empty
  30. * 3: Passwords are not equal
  31. * 4: Passwort is too snort
  32. */
  33. function check_new_pass($pass1, $pass2){
  34. global $PASS_ERR;
  35. global $PASS_ERR_MSG;
  36. // Check if one passwort input is empty
  37. if($pass1 !== "" && $pass2 !== ""){
  38. // Check if password are equal
  39. if($pass1 === $pass2){
  40. // Check if password length is okay
  41. if(strlen($pass1) >= MIN_PASS_LENGTH){
  42. // Password is okay.
  43. return true;
  44. }
  45. else{
  46. // Password is not long enough
  47. $PASS_ERR = 4;
  48. $PASS_ERR_MSG = "Password is not long enough. Please enter a password which has ".MIN_PASS_LENGTH." characters or more.";
  49. return $PASS_ERR;
  50. }
  51. }
  52. else{
  53. // Passwords are not equal
  54. $PASS_ERR = 3;
  55. $PASS_ERR_MSG = "Passwords are not equal.";
  56. return $PASS_ERR;
  57. }
  58. }
  59. else{
  60. // One password is empty.
  61. $PASS_ERR = 2;
  62. $PASS_ERR_MSG = "Not all password fields were filled out";
  63. return $PASS_ERR;
  64. }
  65. }
  66. function get_hash()
  67. {
  68. switch(PASS_HASH_SCHEMA)
  69. {
  70. case "SHA-512":
  71. return '$6$rounds=5000$';
  72. break;
  73. case "SHA-256":
  74. return '$5$rounds=5000$';
  75. break;
  76. case "BLOWFISH":
  77. return '$2a$09$';
  78. break;
  79. }
  80. }
  81. function gen_pass_hash($pass){
  82. $salt = base64_encode(rand(1,1000000) + microtime());
  83. $hash_schema = get_hash();
  84. $pass_hash = crypt($pass, $hash_schema.$salt.'$');
  85. return $pass_hash;
  86. }
  87. function write_pass_hash_to_db($pass_hash, $uid){
  88. global $db;
  89. $uid = $db->escape_string($uid);
  90. $pass_hash = $db->escape_string($pass_hash);
  91. $db->query("UPDATE `".DBT_USERS."` SET `".DBC_USERS_PASSWORD."` = '$pass_hash' WHERE `".DBC_USERS_ID."` = '$uid';");
  92. }
  93. /*
  94. * Add message to logfile
  95. */
  96. function writeLog($text){
  97. if(defined('WRITE_LOG') && defined('WRITE_LOG_PATH')){
  98. $logdestination = realpath(WRITE_LOG_PATH).DIRECTORY_SEPARATOR."webmum.log";
  99. if(is_writable(WRITE_LOG_PATH)){
  100. $logfile = fopen($logdestination, "a") or die("Unable to create or open logfile \"".$logdestination."\" in root directory!");
  101. fwrite($logfile, date('M d H:i:s').": ".$text."\n");
  102. fclose($logfile);
  103. }
  104. else{
  105. die("Directory \"".WRITE_LOG_PATH."\" is not writable");
  106. }
  107. }
  108. }
  109. ?>