PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1 KiB

  1. <?php
  2. /**
  3. * Simple class to represent a user.
  4. */
  5. class UserHandler {
  6. protected $username = null;
  7. public function __construct($username) {
  8. $this->username = $username;
  9. }
  10. /**
  11. * @return boolean true on success; false on failure
  12. * @param string $username
  13. * @param string $old_password
  14. * @param string $new_passwords
  15. *
  16. * All passwords need to be plain text; they'll be hashed appropriately
  17. * as per the configuration in config.inc.php
  18. */
  19. public function change_pass($old_password, $new_password) {
  20. global $config;
  21. $username = $this->username;
  22. $tmp = preg_split ('/@/', $username);
  23. $USERID_DOMAIN = $tmp[1];
  24. $username = escape_string($username);
  25. $table_mailbox = table_by_key('mailbox');
  26. $active = db_get_boolean(True);
  27. $result = db_query("SELECT * FROM $table_mailbox WHERE username='$username' AND active='$active'");
  28. $new_db_password = escape_string(pacrypt($new_password));
  29. $result = db_query ("UPDATE $table_mailbox SET password='$new_db_password',modified=NOW() WHERE username='$username'");
  30. db_log ($username, $USERID_DOMAIN, 'edit_password', "$username");
  31. return true;
  32. }
  33. /**
  34. * Attempt to log a user in.
  35. * @param string $username
  36. * @param string $password
  37. * @return boolean true on successful login (i.e. password matches etc)
  38. */
  39. public static function login($username, $password) {
  40. global $config;
  41. $username = escape_string($username);
  42. $table_mailbox = table_by_key('mailbox');
  43. $active = db_get_boolean(True);
  44. $query = "SELECT password FROM $table_mailbox WHERE username='$username' AND active='$active'";
  45. $result = db_query ($query);
  46. if ($result['rows'] == 1)
  47. {
  48. $row = db_array ($result['result']);
  49. $crypt_password = pacrypt ($password, $row['password']);
  50. if($row['password'] == $crypt_password) {
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56. }
  57. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */