Alternc  latest
Alternc logiel libre pour l'hébergement
change.php
Go to the documentation of this file.
1 <?php
2 
3 @include_once("/etc/squirrelmail/alternc-changepass.conf");
4 if (!defined("ALTERNC_CHANGEPASS_LOC")) {
5  error_log("No configuration for squirrelmail plugin at /etc/squirrelmail/alternc-changepass.conf, please check");
6  exit();
7 }
8 
9 bindtextdomain("alternc", ALTERNC_CHANGEPASS_LOC."/bureau/locales");
10 if (!function_exists("__")) {
11  function __($str) { echo _($str); }
12 }
13 
14  /* ----------------------------------------------------------------- */
15  /** Hashe un mot de passe en clair en MD5 avec un salt aléatoire
16  * @param string $pass Mot de passe à crypter (max 32 caractères)
17  * @return string Retourne le mot de passe crypté
18  * @access private
19  */
20  function _md5cr($pass,$salt="") {
21  if (!$salt) {
22  $chars="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
23  for ($i=0;$i<12;$i++) {
24  $salt.=substr($chars,(mt_rand(0,strlen($chars))),1);
25  }
26  $salt="$1$".$salt;
27  }
28  return crypt($pass,$salt);
29  }
30 
31 $link=mysql_connect(
32  ALTERNC_CHANGEPASS_MYSQL_HOST,
33  ALTERNC_CHANGEPASS_MYSQL_USER,
34  ALTERNC_CHANGEPASS_MYSQL_PASSWORD
35  );
36 if ($link) {
37  mysql_select_db(ALTERNC_CHANGEPASS_MYSQL_DB);
38 } else {
39  __("Can't connect to MySQL server on AlternC!");
40 }
41 
42 
43 define('SM_PATH','../../');
44 
45 /* SquirrelMail required files. */
46 require_once(SM_PATH . 'include/validate.php');
47 require_once(SM_PATH . 'functions/page_header.php');
48 require_once(SM_PATH . 'functions/imap.php');
49 require_once(SM_PATH . 'include/load_prefs.php');
50 
51  /* get globals */
52 sqgetGlobalVar('username', $username, SQ_SESSION);
53 
54 //require_once (SM_PATH . "plugins/alternc_changepass/config.php");
55 //session_start();
56 
57 textdomain("alternc");
58 
60 
61 list($login,$domain)=explode("@",$username,2);
63 
64 if ($_POST['acp_oldpass'] && $_POST['acp_newpass'] && $_POST['acp_verify']) {
65  if ($_POST['acp_newpass']!=$_POST['acp_verify']) {
66  $errstr=_("Your new passwords are differents, pleasy try again.");
67  } else {
68  // Check the old password
69  $r=mysql_query("SELECT a.password, a.id FROM address a,domaines d WHERE a.address='".addslashes($login)."' AND a.domain_id=d.id AND d.domaine='".addslashes($domain)."';");
70  echo mysql_error();
71  if (!($c=mysql_fetch_array($r))) {
72  $errstr=_("Your account has not been found, please try again later or ask an administrator.");
73  } else {
74  if ($c["password"]!=_md5cr($_POST['acp_oldpass'],$c["password"])) {
75  $errstr=_("Your current password is incorrect, please try again.");
76  } else {
77  // FIXME DO Check the password policy :
78  /*
79  if (is_callable(array($admin,"checkPolicy")) &&
80  !$admin->checkPolicy("pop",$username,$_POST['acp_newpass'])) {
81  $errstr=_("This password is not strong enough for your policy, set a stronger password or call your administrator");
82  } else {
83  */
84  // ok, let's change the password
85  $acp_newpass=$_POST['acp_newpass'];
86  $newp=_md5cr($acp_newpass);
87  mysql_query("UPDATE address SET password='".addslashes($newp)."' WHERE id=".$c["id"]." ;");
88  $errstr=_("Your password has been successfully changed. Don't forget to change it in your mail software if you are using one (Outlook, Mozilla, Thunderbird, Eudora ...)");
89 
90  // Write new cookies for the password
91  $onetimepad = OneTimePadCreate(strlen($acp_newpass));
92  sqsession_register($onetimepad,'onetimepad');
93  $key = OneTimePadEncrypt($acp_newpass, $onetimepad);
94  setcookie("key", $key, 0, $base_uri);
95  // }
96  }
97  }
98  }
99 } // POSTED data ?
100 
101 textdomain("squirrelmail");
102 
103 displayPageHeader($color, 'None');
104 
105 textdomain("alternc");
106 
107 if ($errstr) echo "<p><b>".$errstr."</b></p>";
108 
109 ?>
110 
111 <h2><?php __("Changing your mail password"); ?></h2>
112 <form method="post" action="change.php" name="main" id="main">
113  <table>
114  <tr>
115  <th align="right"><label for="acp_oldpass"><?php __("Old Password:"); ?></label></th>
116  <td><input type="password" name="acp_oldpass" id="acp_oldpass" value="" size="20" /></td>
117  </tr>
118 
119  <tr>
120  <th align="right"><label for="acp_newpass"><?php __("New Password:"); ?></label></th>
121  <td><input type="password" name="acp_newpass" id="acp_newpass" value="" size="20" /></td>
122  </tr>
123  <tr>
124  <th align="right"><label for="acp_verify"><?php __("Verify New Password:"); ?></label></th>
125  <td><input type="password" name="acp_verify" id="acp_verify" value="" size="20" /></td>
126  </tr>
127 
128  <tr>
129  <td align="center" colspan="2"><input type="submit" value="<?php __("Change my mail password"); ?>" name="plugin_changepass" /></td>
130  </tr>
131  </table>
132 
133 </form>
134 
135 <script type="text/javascript">
136  document.forms['main'].acp_oldpass.focus();
137  document.forms['main'].setAttribute('autocomplete', 'off');
138 </script>
139 
140 
141 </body></html>
142 <?php
143 
144 textdomain("squirrelmail");
145 
146 ?>
exit
Definition: adm_doadd.php:70
$c
Definition: bootstrap.php:47
$r
Definition: aws_add.php:75
$errstr
Definition: change.php:62
const SM_PATH
Definition: change.php:43
global $base_uri
Definition: change.php:59
global $onetimepad
Definition: change.php:59
global $key
Definition: change.php:59
$link
Definition: change.php:31
if(!function_exists("__")) _md5cr($pass, $salt="")
Hashe un mot de passe en clair en MD5 avec un salt aléatoire.
Definition: change.php:20
global $username
Definition: change.php:59
$domain
Definition: dom_import.php:36
__($str)
Definition: functions.php:404
$login
$i