functions.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * functions.php - Change Password plugin
  4. *
  5. * @copyright &copy; 2003-2007 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage change_password
  10. */
  11. /**
  12. * Will verify the input against a set of criteria:
  13. * is every field supplied, does verify password match,
  14. * does current password validate, ..
  15. * These criteria are (for now) backend-independent.
  16. *
  17. * @return array Array with zero or more error messages.
  18. */
  19. function cpw_check_input()
  20. {
  21. global $cpw_pass_min_length, $cpw_pass_max_length;
  22. // formdata
  23. sqgetGlobalVar('cpw_curpass', $currentpw, SQ_POST);
  24. sqgetGlobalVar('cpw_newpass', $newpw, SQ_POST);
  25. sqgetGlobalVar('cpw_verify', $verifypw, SQ_POST);
  26. // for decrypting current password
  27. sqgetGlobalVar('key', $key, SQ_COOKIE);
  28. sqgetGlobalVar('onetimepad', $onetimepad,SQ_SESSION);
  29. $msg = array();
  30. if(!$newpw) {
  31. $msg[] = _("You must type in a new password.");
  32. }
  33. if(!$verifypw) {
  34. $msg[] = _("You must also type in your new password in the verify box.");
  35. } elseif ($verifypw != $newpw) {
  36. $msg[] = _("Your new password does not match the verify password.");
  37. }
  38. $orig_pw = OneTimePadDecrypt($key, $onetimepad);
  39. if(!$currentpw) {
  40. $msg[] = _("You must type in your current password.");
  41. } elseif ($currentpw != $orig_pw) {
  42. $msg[] = _("Your current password is not correct.");
  43. }
  44. if($newpw && (strlen($newpw) < $cpw_pass_min_length ||
  45. strlen($newpw) > $cpw_pass_max_length ) ) {
  46. $msg[] = sprintf(_("Your new password should be %s to %s characters long."),
  47. $cpw_pass_min_length, $cpw_pass_max_length);
  48. }
  49. // do we need to do checks that are backend-specific and should
  50. // be handled by a hook? I know of none now, bnd those checks can
  51. // also be done in the backend dochange() function. If there turns
  52. // out to be a need for it we can add a hook for that here.
  53. return $msg;
  54. }
  55. define('CPW_CURRENT_NOMATCH', _("Your current password is not correct."));
  56. define('CPW_INVALID_PW', _("Your new password contains invalid characters."));
  57. /**
  58. * Does the actual password changing (meaning it calls the hook function
  59. * from the backend that does this. If something goes wrong, return error
  60. * message(s). If everything ok, change the password in the session so the
  61. * user doesn't have to log out, and redirect back to the options screen.
  62. */
  63. function cpw_do_change()
  64. {
  65. global $cpw_backend;
  66. sqgetGlobalVar('cpw_curpass', $curpw, SQ_POST);
  67. sqgetGlobalVar('cpw_newpass', $newpw, SQ_POST);
  68. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  69. sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
  70. sqgetGlobalVar('key', $key, SQ_COOKIE);
  71. sqgetGlobalVar('username', $username, SQ_SESSION);
  72. require_once(SM_PATH . 'plugins/change_password/backend/'.$cpw_backend.'.php');
  73. $msgs = do_hook('change_password_dochange',
  74. $temp=array (
  75. 'username' => &$username,
  76. 'curpw' => &$curpw,
  77. 'newpw' => &$newpw
  78. ) );
  79. /* something bad happened, return */
  80. if(count($msgs) > 0) {
  81. return $msgs;
  82. }
  83. /* update our password stored in the session */
  84. $onetimepad = OneTimePadCreate(strlen($newpw));
  85. sqsession_register($onetimepad,'onetimepad');
  86. $key = OneTimePadEncrypt($newpw, $onetimepad);
  87. sqsetcookie('key', $key, 0, $base_uri);
  88. /* make sure we write the session data before we redirect */
  89. session_write_close();
  90. header('Location: '.SM_PATH. 'src/options.php?optmode=submit&optpage=change_password&plugin_change_password=1');
  91. exit;
  92. }