Odyssey
MonPass.prg
1 <?php
2  $monLibrary= dirname(__FILE__) . "/../library";
3  $sharedLibrary= dirname(__FILE__) . "/../../shared/library";
4  require_once("$monLibrary/cu_top.i");
5  require_once("$monLibrary/ck_hticket.i");
6  require_once("$monLibrary/cu_pass.i");
7  require_once("$sharedLibrary/errormail.i"); // Be sure errormail is included
8 
9  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
10  // ** Permissions failed
11  // ** redirect to new page
12  header("Location: /hcuadm/hcu_noperm.prg");
13  exit;
14  }
15 
16 $dms_ok=array('action'=>'string','new1'=>'string','new2'=>'string','rowid'=>'string');
17 
18 dms_import($dms_ok);
19 
20 $self = $_SERVER['PHP_SELF'];
21 
22 if (isset($action)) {
23  $msg="";
24  if ($new1 != $new2) {$msg .= "New Passwords Don't Match.<br>"; }
25  if (preg_match("/['\"]/",$new1)){$msg .= "Invalid Characters in New Password.<br>";}
26  if (strlen($new1) < 4) {$msg .= "Password must be at least 4 characters.<br>";}
27  if (strlen($new1) > 0 && !(preg_match("/\d/",$new1) && preg_match("/\D/",$new1))) {
28  $msg .= "Password must contain both number and letter characters!\n";}
29 
30  $dbh = $link;
31 
32  if (empty($msg)){
33  $salt = compute_salt(0);
34  $hash = password_hash($new1, PASSWORD_DEFAULT);
35  $sql= "update cuadminusers set passwd='$hash', forcechange='N',
36  pwchange=now(), failedremain=5
37  where user_name='$rowid'";
38  $sth = db_query($sql,$dbh);
39  if (!$sth) {
40  $msg= "Unable to update password";
41  $notify = new ErrorMail;
42  $notify->mailto='miki@homecu.net';
43  $notify->replyto='miki@homecu.net';
44  $notify->subject='hcuadm/MonPass encountered Error updating password';
45  $notify->msgbody = "\tMonPass Unable to update Master Password\n\n";
46  $notify->msgbody .= "Cu: $rowid\n";
47  $notify->msgbody .= $sql;
48  $notify->file = __FILE__;
49  $notify->cu = $rowid;
50  $notify->SendMail();
51 
52  } else {
53  db_free_result($sth);
54 
55  cu_header("Password Updated");
56  cu_message("Succeeded<br>Password successfully updated");
57  cu_footer();
58  exit;
59 
60  }
61  }
62 }
63 cu_header("Password Change");
64 print <<<EOF
65 <script>
66 function validate()
67 {
68  var strNew1 = document.forms[0].new1.value;
69  var strNew2 = document.forms[0].new2.value;
70  var strMessage = "";
71 
72  // validate user entries
73 
74  if (strNew1.length < 4 || strNew1.length > 8)
75  { strMessage += 'New password must be from 4 to 8 characters long.\\n';}
76  if (strNew1 != strNew2)
77  { strMessage += "New passwords do not match.\\n";}
78  if (strNew1.indexOf("'") != -1 || strNew1.indexOf('"') != -1)
79  { strMessage += "Invalid Characters in New password.\\n";}
80  var boolHasDigit = false;
81  var boolHasChar = false;
82  for (i=0; i < strNew1.length; i++)
83  {
84  ch = strNew1.charAt(i);
85  if (ch >= '0' && ch <= '9')
86  { boolHasDigit = true; }
87  if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <='z'))
88  { boolHasChar = true; }
89  }
90  if ((boolHasDigit == false) || (boolHasChar == false))
91  { strMessage += "Password must contain both number and letter characters.\\n";}
92 
93  if (strMessage.length > 0)
94  {
95  alert(strMessage);
96  return false;
97  }
98 
99 
100  document.forms[0].submit();
101  return true;
102 
103 }
104 </script>
105 EOF;
106 
107 print <<<EOF
108 <CENTER>
109  <FORM NAME=login ACTION="${self}" METHOD=post>
110  <TABLE BORDER=0 width="90%" cellpadding=3 cellspacing=0 class='dmsbg'><tr><td>
111  <TABLE BORDER=0 width="100%" cellpadding=2 cellspacing=0 bgcolor=white>
112  <TR><TD CLASS="bar" align="center" colspan=3>Password Change</TD></TR>
113  <TR>
114  <TD CLASS="hdr" align="right">Master Password:</TD>
115  <TD CLASS="dtl"><INPUT NAME="new1" TYPE="password" SIZE="10" MAXLENGTH="8"
116 ></TD>
117  <TD CLASS="dtl">Password must be from 4 to 8 characters long and contain a
118  combination of numbers and letters</TD>
119  </TR>
120  <TR>
121  <TD CLASS="hdr" align="right">Confirm Master Password:</TD>
122  <TD CLASS="dtl"><INPUT NAME="new2" TYPE="password" SIZE="10" MAXLENGTH="8"
123 ></TD>
124  <TD CLASS="dtl">Enter new password again to confirm</TD>
125  </TR>
126  <TR>
127  <td class='dtl'>&nbsp;</td>
128  <TD CLASS="dtl" colspan=2>
129  <input type=hidden name="action" value="Change Password">
130  <input type=hidden name="rowid" value="$rowid">
131  <INPUT TYPE="button" NAME="BtnSubmit" VALUE=" Change Password " onClick="validate()"></TD></TR>
132  </table>
133  </td></tr></table>
134  </FORM>
135  </BODY></HTML>
136 
137 EOF;
138 ?>