plugins/SpecialUserFuncs.php
changeset 801 eb8b23f11744
parent 799 4629ad98ee88
child 832 7152ca0a0ce9
equal deleted inserted replaced
800:9cdfe82c56cd 801:eb8b23f11744
    10 }
    10 }
    11 **!*/
    11 **!*/
    12 
    12 
    13 /*
    13 /*
    14  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    14  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    15  * Version 1.1.5 (Caoineag alpha 5)
    15  * Version 1.1.6 (Caoineag beta 1)
    16  * Copyright (C) 2006-2008 Dan Fuhry
    16  * Copyright (C) 2006-2008 Dan Fuhry
    17  *
    17  *
    18  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    18  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    19  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    19  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    20  *
    20  *
   118 function page_Special_Login()
   118 function page_Special_Login()
   119 {
   119 {
   120   global $db, $session, $paths, $template, $plugins; // Common objects
   120   global $db, $session, $paths, $template, $plugins; // Common objects
   121   global $__login_status;
   121   global $__login_status;
   122   global $lang;
   122   global $lang;
   123   
       
   124   require_once( ENANO_ROOT . '/includes/diffiehellman.php' );
       
   125   global $dh_supported, $_math;
       
   126   
       
   127   $pubkey = $session->rijndael_genkey();
       
   128   $challenge = $session->dss_rand();
       
   129   
   123   
   130   $locked_out = false;
   124   $locked_out = false;
   131   // are we locked out?
   125   // are we locked out?
   132   $threshold = ( $_ = getConfig('lockout_threshold') ) ? intval($_) : 5;
   126   $threshold = ( $_ = getConfig('lockout_threshold') ) ? intval($_) : 5;
   133   $duration  = ( $_ = getConfig('lockout_duration') ) ? intval($_) : 15;
   127   $duration  = ( $_ = getConfig('lockout_duration') ) ? intval($_) : 15;
   434          <tr>
   428          <tr>
   435            <th colspan="3" style="text-align: center" class="subhead"><input type="submit" name="login" value="Log in" tabindex="<?php echo ( $level <= USER_LEVEL_MEMBER ) ? '4' : '2'; ?>" /></th>
   429            <th colspan="3" style="text-align: center" class="subhead"><input type="submit" name="login" value="Log in" tabindex="<?php echo ( $level <= USER_LEVEL_MEMBER ) ? '4' : '2'; ?>" /></th>
   436          </tr>
   430          </tr>
   437       </table>
   431       </table>
   438     </div>
   432     </div>
   439       <input type="hidden" name="challenge_data" value="<?php echo $challenge; ?>" />
       
   440       <input type="hidden" name="use_crypt" value="no" />
       
   441       <input type="hidden" name="crypt_key" value="<?php echo $pubkey; ?>" />
       
   442       <input type="hidden" name="crypt_data" value="" />
       
   443       <input type="hidden" name="auth_level" value="<?php echo (string)$level; ?>" />
   433       <input type="hidden" name="auth_level" value="<?php echo (string)$level; ?>" />
   444       <?php if ( $level <= USER_LEVEL_MEMBER ): ?>
   434       <?php if ( $level <= USER_LEVEL_MEMBER ): ?>
   445       <script type="text/javascript">
   435       <script type="text/javascript">
   446         document.forms.loginform.username.focus();
   436         document.forms.loginform.username.focus();
   447       </script>
   437       </script>
   449       <script type="text/javascript">
   439       <script type="text/javascript">
   450         document.forms.loginform.pass.focus();
   440         document.forms.loginform.pass.focus();
   451       </script>
   441       </script>
   452       <?php endif; ?>
   442       <?php endif; ?>
   453       <?php
   443       <?php
   454       // 1.1.4
   444       echo $session->generate_aes_form();
   455       
       
   456       require_once( ENANO_ROOT . '/includes/diffiehellman.php' );
       
   457       
       
   458       global $dh_supported, $_math;
       
   459       if ( $dh_supported )
       
   460       {
       
   461         $dh_key_priv = dh_gen_private();
       
   462         $dh_key_pub = dh_gen_public($dh_key_priv);
       
   463         $dh_key_priv = $_math->str($dh_key_priv);
       
   464         $dh_key_pub = $_math->str($dh_key_pub);
       
   465         // store the keys in the DB
       
   466         $q = $db->sql_query('INSERT INTO ' . table_prefix . "diffiehellman( public_key, private_key ) VALUES ( '$dh_key_pub', '$dh_key_priv' );");
       
   467         if ( !$q )
       
   468           $db->_die();
       
   469         
       
   470         echo "<input type=\"hidden\" name=\"dh_supported\" value=\"true\" />
       
   471               <input type=\"hidden\" name=\"dh_public_key\" value=\"$dh_key_pub\" />
       
   472               <input type=\"hidden\" name=\"dh_client_public_key\" value=\"\" />";
       
   473       }
       
   474       else
       
   475       {
       
   476         echo "<input type=\"hidden\" name=\"dh_supported\" value=\"false\" />";
       
   477       }
       
   478       ?>
   445       ?>
   479     </form>
   446     </form>
   480     <?php
   447     <?php
   481       echo $session->aes_javascript('loginform', 'pass', 'use_crypt', 'crypt_key', 'crypt_data', 'challenge_data', 'dh_supported', 'dh_public_key', 'dh_client_public_key');
   448       echo $session->aes_javascript('loginform', 'pass');
   482     ?>
   449     ?>
   483   <?php
   450   <?php
   484   $template->footer();
   451   $template->footer();
   485 }
   452 }
   486 
   453 
   514     $db->close();
   481     $db->close();
   515     exit;
   482     exit;
   516   }
   483   }
   517   if ( isset($_GET['act']) && $_GET['act'] == 'ajaxlogin' )
   484   if ( isset($_GET['act']) && $_GET['act'] == 'ajaxlogin' )
   518   {
   485   {
   519     echo 'This version of the Enano LoginAPI is deprecated. Please use the action.json method instead.';
   486     echo 'This version of the Enano LoginAPI is deprecated. Please clear your browser\'s cache and try your login again. Developers, please use the action.json method instead.';
   520     return true;
   487     return true;
   521   }
   488   }
   522   if(isset($_POST['login']))
   489   if(isset($_POST['login']))
   523   {
   490   {
   524     $captcha_hash = ( isset($_POST['captcha_hash']) ) ? $_POST['captcha_hash'] : false;
   491     $captcha_hash = ( isset($_POST['captcha_hash']) ) ? $_POST['captcha_hash'] : false;
   525     $captcha_code = ( isset($_POST['captcha_code']) ) ? $_POST['captcha_code'] : false;
   492     $captcha_code = ( isset($_POST['captcha_code']) ) ? $_POST['captcha_code'] : false;
   526     if ( $_POST['use_crypt'] == 'yes' )
   493     
   527     {
   494     try
   528       $result = $session->login_with_crypto($_POST['username'], $_POST['crypt_data'], $_POST['crypt_key'], $_POST['challenge_data'], intval($_POST['auth_level']), $captcha_hash, $captcha_code, isset($_POST['remember']));
   495     {
   529     }
   496       $password = $session->get_aes_post('pass');
   530     else if ( $_POST['use_crypt'] == 'yes_dh' )
   497     }
   531     {
   498     catch ( Exception $e )
   532       // retrieve and decrypt the password using DiffieHellman
   499     {
   533       
   500       $__login_status = array(
   534       require_once( ENANO_ROOT . '/includes/diffiehellman.php' );
   501         'mode' => 'error',
   535       global $dh_supported, $_math;
   502         'error' => $e->getMessage()
   536       
   503       );
   537       if ( !$dh_supported )
   504       return false;
   538       {
   505     }
   539         die_semicritical('DiffieHellman error', 'Server does not support DiffieHellman, denying logon request');
   506     
   540       }
   507     $result = $session->login_without_crypto($_POST['username'], $password, false, intval($_POST['auth_level']), $captcha_hash, $captcha_code, isset($_POST['remember']));
   541       
       
   542       // Fetch private key
       
   543       $dh_public = $_POST['dh_public_key'];
       
   544       if ( !preg_match('/^[0-9]+$/', $dh_public) )
       
   545       {
       
   546         $__login_status = array(
       
   547           'success' => false,
       
   548           'error' => 'ERR_DH_KEY_NOT_INTEGER',
       
   549           'debug' => "public key: $dh_public"
       
   550         );
       
   551         return false;
       
   552       }
       
   553       $q = $db->sql_query('SELECT private_key, key_id FROM ' . table_prefix . "diffiehellman WHERE public_key = '$dh_public';");
       
   554       if ( !$q )
       
   555         $db->die_json();
       
   556       
       
   557       if ( $db->numrows() < 1 )
       
   558       {
       
   559         $__login_status = array(
       
   560           'success' => false,
       
   561           'error' => 'ERR_DH_KEY_NOT_FOUND',
       
   562           'debug' => "public key: $dh_public"
       
   563         );
       
   564         return false;
       
   565       }
       
   566       
       
   567       list($dh_private, $dh_key_id) = $db->fetchrow_num();
       
   568       $db->free_result();
       
   569       
       
   570       // We have the private key, now delete the key pair, we no longer need it
       
   571       $q = $db->sql_query('DELETE FROM ' . table_prefix . "diffiehellman WHERE key_id = $dh_key_id;");
       
   572       if ( !$q )
       
   573         $db->die_json();
       
   574       
       
   575       // Generate the shared secret
       
   576       $dh_secret = dh_gen_shared_secret($dh_private, $_POST['dh_client_public_key']);
       
   577       $dh_secret = $_math->str($dh_secret);
       
   578       
       
   579       // Did we get all our math right?
       
   580       $dh_secret_check = sha1($dh_secret);
       
   581       $dh_hash = $_POST['crypt_key'];
       
   582       if ( $dh_secret_check !== $dh_hash )
       
   583       {
       
   584         $__login_status = array(
       
   585           'success' => false,
       
   586           'error' => 'ERR_DH_HASH_NO_MATCH',
       
   587           'debug' => "dh_secret_check = $dh_secret_check\ndh_hash_input = $dh_hash"
       
   588         );
       
   589         return false;
       
   590       }
       
   591       
       
   592       // All good! Generate the AES key
       
   593       $aes_key = substr(sha256($dh_secret), 0, ( AES_BITS / 4 ));
       
   594       
       
   595       // decrypt user info
       
   596       $aes_key = hexdecode($aes_key);
       
   597       $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE);
       
   598       $password = $aes->decrypt($_POST['crypt_data'], $aes_key, ENC_HEX);
       
   599       
       
   600       $result = $session->login_without_crypto($_POST['username'], $password, false, intval($_POST['auth_level']), $captcha_hash, $captcha_code, isset($_POST['remember']));
       
   601     }
       
   602     else
       
   603     {
       
   604       $result = $session->login_without_crypto($_POST['username'], $_POST['pass'], false, intval($_POST['auth_level']), $captcha_hash, $captcha_code, isset($_POST['remember']));
       
   605     }
       
   606    
   508    
   607     if($result['success'])
   509     if($result['success'])
   608     {
   510     {
   609       $session->start();
   511       $session->start();
   610       
   512       
  1596   global $lang;
  1498   global $lang;
  1597   
  1499   
  1598   $template->header();
  1500   $template->header();
  1599   if($paths->getParam(0) == 'stage2')
  1501   if($paths->getParam(0) == 'stage2')
  1600   {
  1502   {
       
  1503     require_once(ENANO_ROOT . '/includes/math.php');
       
  1504     require_once(ENANO_ROOT . '/includes/diffiehellman.php');
       
  1505     
  1601     $user_id = intval($paths->getParam(1));
  1506     $user_id = intval($paths->getParam(1));
  1602     $encpass = $paths->getParam(2);
  1507     $encpass = $paths->getParam(2);
  1603     if ( $user_id < 2 )
  1508     if ( $user_id < 2 )
  1604     {
  1509     {
  1605       echo '<p>Hacking attempt</p>';
  1510       echo '<p>Hacking attempt</p>';
  1611       echo '<p>Hacking attempt</p>';
  1516       echo '<p>Hacking attempt</p>';
  1612       $template->footer();
  1517       $template->footer();
  1613       return false;
  1518       return false;
  1614     }
  1519     }
  1615     
  1520     
  1616     $q = $db->sql_query('SELECT username,temp_password_time FROM '.table_prefix.'users WHERE user_id='.$user_id.' AND temp_password=\'' . $encpass . '\';');
  1521     $q = $db->sql_query('SELECT username,temp_password_time,temp_password,password_salt FROM '.table_prefix.'users WHERE user_id='.$user_id.';');
  1617     if($db->numrows() < 1)
  1522     if($db->numrows() < 1)
  1618     {
  1523     {
  1619       echo '<p>Invalid credentials</p>';
  1524       echo '<p>Invalid credentials</p>';
  1620       $template->footer();
  1525       $template->footer();
  1621       return false;
  1526       return false;
  1622     }
  1527     }
  1623     $row = $db->fetchrow();
  1528     $row = $db->fetchrow();
  1624     $db->free_result();
  1529     $db->free_result();
  1625     
  1530     
       
  1531     $temp_pass = $session->pk_decrypt($encpass);
       
  1532     $temp_hmac = hmac_sha1($temp_pass, $row['password_salt']);
       
  1533     
       
  1534     if ( $temp_hmac !== $row['temp_password'] )
       
  1535     {
       
  1536       echo '<p>Invalid credentials</p>';
       
  1537       $template->footer();
       
  1538       return false;
       
  1539     }
       
  1540     
  1626     if ( ( intval($row['temp_password_time']) + ( 3600 * 24 ) ) < time() )
  1541     if ( ( intval($row['temp_password_time']) + ( 3600 * 24 ) ) < time() )
  1627     {
  1542     {
  1628       echo '<p>' . $lang->get('userfuncs_passreset_err_pass_expired', array('reset_url' => makeUrlNS('Special', 'PasswordReset'))) . '</p>';
  1543       echo '<p>' . $lang->get('userfuncs_passreset_err_pass_expired', array('reset_url' => makeUrlNS('Special', 'PasswordReset'))) . '</p>';
  1629       $template->footer();
  1544       $template->footer();
  1630       return false;
  1545       return false;
  1631     }
  1546     }
  1632     
  1547     
  1633     if ( isset($_POST['do_stage2']) )
  1548     if ( isset($_POST['do_stage2']) )
  1634     {
  1549     {
  1635       $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE);
  1550       $data = $session->get_aes_post('pass');
  1636       if($_POST['use_crypt'] == 'yes')
  1551       
  1637       {
  1552       if(empty($data))
  1638         $crypt_key = $session->fetch_public_key($_POST['crypt_key']);
  1553       {
  1639         if(!$crypt_key)
  1554         echo 'ERROR: Sanity check failed!';
       
  1555         $template->footer();
       
  1556         return false;
       
  1557       }
       
  1558       if ( strlen($data) < 6 )
       
  1559       {
       
  1560         echo '<p>' . $lang->get('userfuncs_passreset_err_too_short') . '</p>';
       
  1561         $template->footer();
       
  1562         return false;
       
  1563       }
       
  1564       if ( $_POST['use_crypt'] == 'no' )
       
  1565       {
       
  1566         if ( $_POST['pass'] !== $_POST['pass_confirm'] )
  1640         {
  1567         {
  1641           echo $lang->get('user_err_key_not_found');
  1568           echo '<p>' . $lang->get('userfuncs_passreset_err_no_match') . '</p>';
  1642           $template->footer();
  1569           $template->footer();
  1643           return false;
  1570           return false;
  1644         }
  1571         }
  1645         $crypt_key = hexdecode($crypt_key);
       
  1646         $data = $aes->decrypt($_POST['crypt_data'], $crypt_key, ENC_HEX);
       
  1647         if(strlen($data) < 6)
       
  1648         {
       
  1649           echo $lang->get('userfuncs_passreset_err_too_short');
       
  1650           $template->footer();
       
  1651           return false;
       
  1652         }
       
  1653       }
       
  1654       else
       
  1655       {
       
  1656         $data = $_POST['pass'];
       
  1657         $conf = $_POST['pass_confirm'];
       
  1658         if($data != $conf)
       
  1659         {
       
  1660           echo $lang->get('userfuncs_passreset_err_no_match');
       
  1661           $template->footer();
       
  1662           return false;
       
  1663         }
       
  1664         if(strlen($data) < 6)
       
  1665         {
       
  1666           echo $lang->get('userfuncs_passreset_err_too_short');
       
  1667           $template->footer();
       
  1668           return false;
       
  1669         }
       
  1670       }
       
  1671       if(empty($data))
       
  1672       {
       
  1673         echo 'ERROR: Sanity check failed!';
       
  1674         $template->footer();
       
  1675         return false;
       
  1676       }
  1572       }
  1677       if ( getConfig('pw_strength_enable') == '1' )
  1573       if ( getConfig('pw_strength_enable') == '1' )
  1678       {
  1574       {
  1679         $min_score = intval(getConfig('pw_strength_minimum'));
  1575         $min_score = intval(getConfig('pw_strength_minimum'));
  1680         $inp_score = password_score($data);
  1576         $inp_score = password_score($data);
  1684           echo "<p>" . $lang->get('userfuncs_passreset_err_failed_score', array('inp_score' => $inp_score, 'url' => $url)) . "</p>";
  1580           echo "<p>" . $lang->get('userfuncs_passreset_err_failed_score', array('inp_score' => $inp_score, 'url' => $url)) . "</p>";
  1685           $template->footer();
  1581           $template->footer();
  1686           return false;
  1582           return false;
  1687         }
  1583         }
  1688       }
  1584       }
  1689       $encpass = $session->pk_encrypt($data, ENC_HEX);
  1585       
  1690       $q = $db->sql_query('UPDATE '.table_prefix.'users SET password=\'' . $encpass . '\',temp_password=\'\',temp_password_time=0 WHERE user_id='.$user_id.';');
  1586       $session->set_password($user_id, $data);
       
  1587       
       
  1588       $q = $db->sql_query('UPDATE '.table_prefix.'users SET temp_password=\'\',temp_password_time=0 WHERE user_id = '.$user_id.';');
  1691       
  1589       
  1692       if($q)
  1590       if($q)
  1693       {
  1591       {
  1694         $session->login_without_crypto($row['username'], $data);
  1592         $session->login_without_crypto($row['username'], $data);
  1695         echo '<p>' . $lang->get('userfuncs_passreset_stage2_success', array('url_mainpage' => makeUrl(get_main_page()))) . '</p>';
  1593         echo '<p>' . $lang->get('userfuncs_passreset_stage2_success', array('url_mainpage' => makeUrl(get_main_page()))) . '</p>';
  1702       $template->footer();
  1600       $template->footer();
  1703       return false;
  1601       return false;
  1704     }
  1602     }
  1705     
  1603     
  1706     // Password reset form
  1604     // Password reset form
  1707     $pubkey = $session->rijndael_genkey();
       
  1708     
       
  1709     $evt_get_score = ( getConfig('pw_strength_enable') == '1' ) ? 'onkeyup="password_score_field(this);" ' : '';
  1605     $evt_get_score = ( getConfig('pw_strength_enable') == '1' ) ? 'onkeyup="password_score_field(this);" ' : '';
  1710     $pw_meter =      ( getConfig('pw_strength_enable') == '1' ) ? '<tr><td class="row1">' . $lang->get('userfuncs_passreset_stage2_lbl_strength') . '</td><td class="row1"><div id="pwmeter"></div><script type="text/javascript">password_score_field(document.forms.resetform.pass);</script></td></tr>' : '';
  1606     $pw_meter =      ( getConfig('pw_strength_enable') == '1' ) ? '<tr><td class="row1">' . $lang->get('userfuncs_passreset_stage2_lbl_strength') . '</td><td class="row1"><div id="pwmeter"></div></td></tr>' : '';
  1711     $pw_blurb =      ( getConfig('pw_strength_enable') == '1' && intval(getConfig('pw_strength_minimum')) > -10 ) ? '<br /><small>' . $lang->get('userfuncs_passreset_stage2_blurb_strength') . '</small>' : '';
  1607     $pw_blurb =      ( getConfig('pw_strength_enable') == '1' && intval(getConfig('pw_strength_minimum')) > -10 ) ? '<br /><small>' . $lang->get('userfuncs_passreset_stage2_blurb_strength') . '</small>' : '';
  1712     
  1608     
  1713     ?>
  1609     ?>
  1714     <form action="<?php echo makeUrl($paths->fullpage); ?>" method="post" name="resetform" onsubmit="return runEncryption();">
  1610     <form action="<?php echo makeUrl($paths->fullpage); ?>" method="post" name="resetform" onsubmit="return runEncryption();">
  1715       <br />
  1611       <br />
  1719           <tr><td class="row1"><?php echo $lang->get('userfuncs_passreset_stage2_lbl_password'); ?> <?php echo $pw_blurb; ?></td><td class="row1"><input name="pass" type="password" <?php echo $evt_get_score; ?>/></td></tr>
  1615           <tr><td class="row1"><?php echo $lang->get('userfuncs_passreset_stage2_lbl_password'); ?> <?php echo $pw_blurb; ?></td><td class="row1"><input name="pass" type="password" <?php echo $evt_get_score; ?>/></td></tr>
  1720           <tr><td class="row2"><?php echo $lang->get('userfuncs_passreset_stage2_lbl_confirm'); ?> </td><td class="row2"><input name="pass_confirm" type="password" /></td></tr>
  1616           <tr><td class="row2"><?php echo $lang->get('userfuncs_passreset_stage2_lbl_confirm'); ?> </td><td class="row2"><input name="pass_confirm" type="password" /></td></tr>
  1721           <?php echo $pw_meter; ?>
  1617           <?php echo $pw_meter; ?>
  1722           <tr>
  1618           <tr>
  1723             <td colspan="2" class="row3" style="text-align: center;">
  1619             <td colspan="2" class="row3" style="text-align: center;">
  1724               <input type="hidden" name="use_crypt" value="no" />
  1620               
  1725               <input type="hidden" name="crypt_key" value="<?php echo $pubkey; ?>" />
       
  1726               <input type="hidden" name="crypt_data" value="" />
       
  1727               <input type="submit" name="do_stage2" value="<?php echo $lang->get('userfuncs_passreset_stage2_btn_submit'); ?>" />
  1621               <input type="submit" name="do_stage2" value="<?php echo $lang->get('userfuncs_passreset_stage2_btn_submit'); ?>" />
  1728             </td>
  1622             </td>
  1729           </tr>
  1623           </tr>
  1730         </table>
  1624         </table>
  1731       </div>
  1625       </div>
       
  1626       <?php echo $session->generate_aes_form(); ?>
  1732     </form>
  1627     </form>
  1733     <script type="text/javascript">
  1628     <script type="text/javascript">
  1734     if ( !KILL_SWITCH )
  1629     addOnloadHook(function()
  1735     {
  1630       {
  1736       disableJSONExts();
  1631         load_component('pwstrength');
  1737       str = '';
  1632         password_score_field(document.forms.resetform.pass);
  1738       for(i=0;i<keySizeInBits/4;i++) str+='0';
  1633       });
  1739       var key = hexToByteArray(str);
       
  1740       var pt = hexToByteArray(str);
       
  1741       var ct = rijndaelEncrypt(pt, key, "ECB");
       
  1742       var ct = byteArrayToHex(ct);
       
  1743       switch(keySizeInBits)
       
  1744       {
       
  1745         case 128:
       
  1746           v = '66e94bd4ef8a2c3b884cfa59ca342b2e';
       
  1747           break;
       
  1748         case 192:
       
  1749           v = 'aae06992acbf52a3e8f4a96ec9300bd7aae06992acbf52a3e8f4a96ec9300bd7';
       
  1750           break;
       
  1751         case 256:
       
  1752           v = 'dc95c078a2408989ad48a21492842087dc95c078a2408989ad48a21492842087';
       
  1753           break;
       
  1754       }
       
  1755       var testpassed = ( ct == v && md5_vm_test() );
       
  1756       var frm = document.forms.resetform;
       
  1757       if(testpassed)
       
  1758       {
       
  1759         frm.use_crypt.value = 'yes';
       
  1760         var cryptkey = frm.crypt_key.value;
       
  1761         frm.crypt_key.value = hex_md5(cryptkey);
       
  1762         cryptkey = hexToByteArray(cryptkey);
       
  1763         if(!cryptkey || ( ( typeof cryptkey == 'string' || typeof cryptkey == 'object' ) ) && cryptkey.length != keySizeInBits / 8 )
       
  1764         {
       
  1765           frm._login.disabled = true;
       
  1766           len = ( typeof cryptkey == 'string' || typeof cryptkey == 'object' ) ? '\nLen: '+cryptkey.length : '';
       
  1767           alert('The key is messed up\nType: '+typeof(cryptkey)+len);
       
  1768         }
       
  1769       }
       
  1770       function runEncryption()
       
  1771       {
       
  1772         var frm = document.forms.resetform;
       
  1773         pass1 = frm.pass.value;
       
  1774         pass2 = frm.pass_confirm.value;
       
  1775         if ( pass1 != pass2 )
       
  1776         {
       
  1777           alert($lang.get('userfuncs_passreset_err_no_match'));
       
  1778           return false;
       
  1779         }
       
  1780         if ( pass1.length < 6 )
       
  1781         {
       
  1782           alert($lang.get('userfuncs_passreset_err_too_short'));
       
  1783           return false;
       
  1784         }
       
  1785         if(testpassed)
       
  1786         {
       
  1787           pass = frm.pass.value;
       
  1788           pass = stringToByteArray(pass);
       
  1789           cryptstring = rijndaelEncrypt(pass, cryptkey, 'ECB');
       
  1790           if(!cryptstring)
       
  1791           {
       
  1792             return false;
       
  1793           }
       
  1794           cryptstring = byteArrayToHex(cryptstring);
       
  1795           frm.crypt_data.value = cryptstring;
       
  1796           frm.pass.value = "";
       
  1797           frm.pass_confirm.value = "";
       
  1798         }
       
  1799         return true;
       
  1800       }
       
  1801     }
       
  1802     </script>
  1634     </script>
  1803     <?php
  1635     <?php
       
  1636     echo $session->aes_javascript('resetform', 'pass', 'use_crypt', 'crypt_key', 'crypt_data', 'challenge_data', 'dh_supported', 'dh_public_key', 'dh_client_public_key');
  1804     $template->footer();
  1637     $template->footer();
  1805     return true;
  1638     return true;
  1806   }
  1639   }
  1807   if ( $session->user_logged_in )
  1640   if ( $session->user_logged_in )
  1808   {
  1641   {