home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / public / chpwd.php < prev    next >
Encoding:
PHP Script  |  2003-04-14  |  2.4 KB  |  80 lines

  1. <?php /* PUBLIC $Id: chpwd.php,v 1.4 2003/04/14 11:40:20 eddieajau Exp $ */
  2. $user_id = @$AppUI->user_id;
  3.  
  4. // check for a non-zero user id
  5. if ($user_id) {
  6.     $old_pwd = db_escape( trim( dPgetParam( $_POST, 'old_pwd', null ) ) );
  7.     $new_pwd1 = db_escape( trim( dPgetParam( $_POST, 'new_pwd1', null ) ) );
  8.     $new_pwd2 = db_escape( trim( dPgetParam( $_POST, 'new_pwd2', null ) ) );
  9.  
  10.     // has the change form been posted
  11.     if ($old_pwd && $new_pwd1 && $new_pwd2 && $new_pwd1 == $new_pwd2 ) {
  12.         // check that the old password matches
  13.         $sql = "SELECT user_id FROM users WHERE user_password = MD5('$old_pwd') AND user_id=$user_id";
  14.         if (db_loadResult( $sql ) == $user_id) {
  15.             require_once( "{$AppUI->cfg['root_dir']}/modules/admin/admin.class.php" );
  16.             $user = new CUser();
  17.             $user->user_id = $user_id;
  18.             $user->user_password = $new_pwd1;
  19.  
  20.             if (($msg = $user->store())) {
  21.                 $AppUI->setMsg( $msg, UI_MSG_ERROR );
  22.             } else {
  23.                 echo $AppUI->_('chgpwUpdated');
  24.             }
  25.         } else {
  26.             echo $AppUI->_('chgpwWrongPW');
  27.         }
  28.     } else {
  29. ?>
  30. <script language="javascript">
  31. function submitIt() {
  32.     var f = document.frmEdit;
  33.     var msg = '';
  34.  
  35.     if (f.old_pwd.value.length < 3) {
  36.         msg += "\n<?php echo $AppUI->_('chgpwValidOld');?>";
  37.         f.old_pwd.focus();
  38.     }
  39.     if (f.new_pwd1.value.length < 3) {
  40.         msg += "\n<?php echo $AppUI->_('chgpwValidNew');?>";
  41.         f.new_pwd1.focus();
  42.     }
  43.     if (f.new_pwd1.value != f.new_pwd2.value) {
  44.         msg += "\n<?php echo $AppUI->_('chgpwNoMatch');?>";
  45.         f.new_pwd2.focus();
  46.     }
  47.     if (msg.length < 1) {
  48.         f.submit();
  49.     } else {
  50.         alert(msg);
  51.     }
  52. }
  53. </script>
  54. <h1><?php echo $AppUI->_('Change User Password');?></h1>
  55. <table width="100%" cellspacing="0" cellpadding="4" border="0" class="std">
  56. <form name="frmEdit" method="post" onsubmit="return false">
  57. <tr>
  58.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Current Password');?></td>
  59.     <td><input type="password" name="old_pwd" class="text"></td>
  60. </tr>
  61. <tr>
  62.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_('New Password');?></td>
  63.     <td><input type="password" name="new_pwd1" class="text"></td>
  64. </tr>
  65. <tr>
  66.     <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Repeat New Password');?></td>
  67.     <td><input type="password" name="new_pwd2" class="text"></td>
  68. </tr>
  69. <tr>
  70.     <td> </td>
  71.     <td align="right" nowrap="nowrap"><input type="button" value="<?php echo $AppUI->_('submit');?>" onclick="submitIt()" class="button"></td>
  72. </tr>
  73. <form>
  74. </table>
  75. <?php
  76.     }
  77. } else {
  78.     echo $AppUI->_('chgpwLogin');
  79. }
  80. ?>