util.php 897 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. function check_login() {
  3. if (isset($_SESSION['login']) && $_SESSION ['login'] === true) {
  4. return true;
  5. }
  6. return false;
  7. }
  8. function read_config() {
  9. return parse_ini_file('config/config.ini');
  10. }
  11. function check_password_quality($pwd) {
  12. if (!isset($pwd)||strlen($pwd)<4) {
  13. return false;
  14. }
  15. return true;
  16. }
  17. function check_username($username) {
  18. if (!isset($username)||strlen($username)>20 || strlen($username)<3) {
  19. return false;
  20. }
  21. return preg_match('/^[a-zA-Z0-9]+$/', $username);
  22. }
  23. function random_password($length) {
  24. $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ1234567890';
  25. $pass = array(); //remember to declare $pass as an array
  26. $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  27. for ($i = 0; $i < $length; $i++) {
  28. $n = rand(0, $alphaLength);
  29. $pass[] = $alphabet[$n];
  30. }
  31. return implode($pass); //turn the array into a string
  32. }
  33. ?>