Menambahkan Fitur Lupa Password untuk Petugas ke dalam osTicket v1.6 RC5

Umumnya, di sistem manapun yang membutuhkan kata sandi (password) sebagai syarat untuk mencatat masuk (login) ke dalam sistem, selalu disediakan fitur Lupa Password supaya pengguna sistem tersebut dapat mereset lalu mendapatkan password yang baru. Sayangnya, fitur ini tidak terdapat di Sistem osTicket, baik versi 1.6 RC4 maupun 1.6 RC5. Jadi, saya membuat modifikasi baru dengan menambahkan fitur ini ke dalam osTicket versi 1.6 RC5. Ketika petugas lupa dengan kata sandi mereka, maka mereka mengklik link Lupa Password, memasukkan email mereka, dan klik tombol Send New Password. Setelah itu, Sistem osTicket akan mengirim sebuah kode aktivasi termasuk link URL untuk mengaktifkan password baru tadi. Setelah petugas mengaktifkannya, maka password baru akan dikirim ke email mereka.

Anda juga dapat membaca topik yang saya kirim ke Forum osTicket melalui tautan berikut:
[MOD] Forgot Admin/Manager/Staff Password.

Untuk mengimplementasikan secara lengkap modifikasi ini, silahkan ikuti langkah-langkah berikut dengan teliti:

  1. Pertama sekali, Anda harus menambahkan dua field baru ke dalam tabel ost_staff di database yang digunakan oleh Sistem osTicket Anda. Jalankan skrip SQL berikut. Anda dapat menggunakan phpMyAdmin atau tool MySQL lainnya:

    ALTER TABLE ost_staff 
    ADD COLUMN `new_passwd` varchar(128) NULL,
    ADD COLUMN `new_passwd_activate` varchar(128) NULL;
  2. Buka file \include\staff\login.tpl.php, dan cari kode ini:

    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    <body id="loginBody">
    <h1 id="logo"><a href="index.php">osTicket Staff Control Panel</a></h1>
    <div id="loginBox">
      <h1 style="clear: both;"><?=$msg?></h1>
      <form action="login.php" method="post">
      <input type="hidden" name=do value="scplogin" />
        <table border=0 align="center">
            <tr><td width=100px align="right"><b>Username</b>:</td><td><input type="text" name="username" id="name" value="" /></td></tr>
            <tr><td align="right"><b>Password</b>:</td><td><input type="password" name="passwd" id="pass" /></td></tr>
            <tr><td>&nbsp;</td><td>&nbsp;&nbsp;<input class="submit" type="submit" name="submit" value="Login" /></td></tr>
        </table>
    </form>
    </div>
    <div id="copyRights">Copyright &copy; <a href='http://www.osticket.com' target="_blank">osTicket.com</a></div>
    </body>
    </html>

    lalu timpa dengan kode berikut ini:

    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    <body id="loginBody" onload="document.frmLogin.username.focus()">
    <h1 id="logo"><a href="index.php">osTicket Staff Control Panel</a></h1>
    <div id="loginBox">
      <h1 style="clear: both;"><?=$msg?></h1>
      <form name="frmLogin" action="login.php" method="post">
      <input type="hidden" name=do value="scplogin" />
        <table border=0 align="center">
            <tr><td width=100px align="right"><b>Username</b>:</td><td><input type="text" name="username" id="name" value="" /></td></tr>
            <tr><td align="right"><b>Password</b>:</td><td><input type="password" name="passwd" id="pass" /></td></tr>
            <tr><td>&nbsp;</td><td><input class="submit" type="submit" name="submit" value="Login" /></td></tr>
        </table>
    </form>
    </div>
    <div><br />&nbsp;<a href="forgotpassword.php">Forgot Password?</a></div><br />
    <div id="copyRights">Copyright &copy; <a href='http://www.osticket.com' target="_blank">osTicket.com</a></div>
    </body>
    </html>
  3. Buat sebuah file baru dan beri nama dengan forgotpassword.tpl.php lalu salin dan tempelkan kode berikut ke dalam file tersebut, dan setelah itu, letakkan file ini di dalam sub direktori \include\staff\:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    
    <?php
     
    /**
     * @author Masino Sinaga, http://www.openscriptsolution.com
     * @copyright October 11, 2009
     */
    ?>
     
    <?php defined('OSTSCPINC') or die('Invalid path'); ?>
     
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>osTicket:: SCP Login</title>
    <link rel="stylesheet" href="css/login.css" type="text/css" />
    <meta name="robots" content="noindex" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    </head>
     
    <body id="loginBody" onload="document.frmForgotPassword.email.focus()">
    <h1 id="logo"><a href="index.php">osTicket Staff Control Panel</a></h1>
    <div id="loginBox">
     
    	<h1 style="clear: both;"><?php echo $forgotmsg; ?></h1>
    	<form name="frmForgotPassword" action="forgotpassword.php" method="post">
    	<input type="hidden" name=do value="scplogin" />
        <table border=0 align="center">
            <tr><td align="right"><b>Email</b>:</td><td><input type="email" name="email" id="email" /></td></tr>
            <tr><td>&nbsp;</td><td>&nbsp;&nbsp;<input class="submit" type="submit" name="submit" value="Send My New Password" /></td></tr>
        </table>
    </form>
    </div>
            <label>&nbsp;</label>
            <div><a href="index.php">Back to Index SCP</a></div>
    	<br />
     
    <div id="copyRights">Copyright &copy; <a href='http://www.osticket.com' target="_blank">osTicket.com</a></div>
    </body>
    </html>
  4. Buat sebuah file baru dan beri nama dengan forgotpassword.php lalu salin dan tempelkan kode berikut ke dalam file tersebut, dan setelah itu, letakkan file ini ke dalam sub direktori \scp\:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    
    <?php
     
    /**
     * @author Masino Sinaga, http://www.openscriptsolution.com
     * @copyright October 11, 2009
     */
     
    require_once('../main.inc.php');
     
    ?>
     
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>osTicket:: SCP Login</title>
    <link rel="stylesheet" href="css/login.css" type="text/css" />
    <meta name="robots" content="noindex" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    </head>
     
    <?php
     
    $forgotmsg='Email Required';
    if($_POST && (!empty($_POST['email']) )) {
      $email=trim($_POST['email']);
     
      $sqle='SELECT email, username, new_passwd FROM '.STAFF_TABLE.
            ' WHERE email='.db_input($email).'';
      $respe=db_query($sqle);
      $countRec = db_num_rows($respe);
     
      if ($countRec > 0) {
     
        while ($row = db_fetch_array($respe)) {
          $username = $row['username'];
        }
     
        $key_len = 54 - 20;
        $key_len = max(6, $key_len); // we want at least 6
        $key_len = (8) ? min($key_len, 8) : $key_len; // we want at most 8
        $user_actkey = substr(gen_rand_string(10), 0, $key_len);
        $user_password = gen_rand_string(8);
     
        $sql = "UPDATE ".STAFF_TABLE.
                " SET new_passwd='".$user_password."', new_passwd_activate='".$user_actkey. 
                "' WHERE email=".db_input($email)."";
     
        if(db_query($sql) && db_affected_rows($res)){
          global $cfg;
          $helpdesk_email=$cfg->getDefaultEmail();
          $helpdesk_url=$cfg->getUrl();
          $helpdesk_title=$cfg->getTitle();
          if($helpdesk_email){
            $helpdesk_email->send($email, 'Activation Key for New Password', ''.$username.', You are receiving this notification because you have (or someone pretending to be you has) requested a new password be sent for your account on "'.$helpdesk_title.'". If you did not request this notification then please ignore it, if you keep receiving it please contact your Administrator. Otherwise, to use the new password you need to activate it. To do this, please click on this link: '.$helpdesk_url.'scp/activatepassword.php?key='.$user_actkey);
          }
     
          echo '<body id="loginBody" onload="document.frmForgotPassword.email.focus()">
                <h1 id="logo"><a href="index.php">osTicket Staff Control Panel</a></h1>
                <div id="loginBox">';
          echo '<br />We have sent the URL to your email in order to activate your new password. Check your email in a few minutes!<br /><br />';
          echo '<div id="copyRights">Copyright &copy; <a href="http://www.osticket.com" target="_blank">osTicket.com</a></div>
                </body>
                </html>';  
          exit;
     
        } else {
          echo '<body id="loginBody" onload="document.frmForgotPassword.email.focus()">
                <h1 id="logo"><a href="index.php">osTicket Staff Control Panel</a></h1>
                <div id="loginBox">';
    			echo 'Failed send URL to your email. Please try again later!<br /><br />';
          echo '<div id="copyRights">Copyright &copy; <a href="http://www.osticket.com" target="_blank">osTicket.com</a></div>
                </body>
                </html>';			
          exit;
        }    
     
      } else {		
     
        echo '<body id="loginBody" onload="document.frmForgotPassword.email.focus()">
              <h1 id="logo"><a href="index.php">osTicket Staff Control Panel</a></h1>
              <div id="loginBox">';
        echo '<br />Sorry, but that email does not exist in our system.<br /><br />';
        echo '<a href="index.php">Login</a><br /><br />';
        echo '<div id="copyRights">Copyright &copy; <a href="http://www.osticket.com" target="_blank">osTicket.com</a></div>
              </body>
              </html>';		
        exit;		
        }
    }
     
    define("OSTSCPINC",TRUE); //Make includes happy!
    include_once(INCLUDE_DIR.'staff/forgotpassword.tpl.php');
     
    /** Just additional function, please be kind... ;-) **/
     
    /**
    * Generates an alphanumeric random string of given length
    */
    function gen_rand_string($num_chars = 8)
    {
    	$rand_str = unique_id();
    	$rand_str = str_replace('0', 'Z', strtoupper(base_convert($rand_str, 16, 35)));
     
    	return substr($rand_str, 0, $num_chars);
    }
     
    /**
    * Return unique id
    * @param string $extra additional entropy
    */
    function unique_id($extra = 'c')
    {
    	static $dss_seeded = false;
    	global $config;
    	$val = '4cc5d71c0f7208b4c7708e3c6ae41d10' . microtime();
    	$val = md5($val);
    	return substr($val, 4, 16);
    }
     
    ?>
  5. Buat sebuah file baru dan beri nama dengan activatepassword.php lalu salin dan tempelkan kode berikut ini ke dalam file tadi, dan setelah itu, letakkan file ini ke dalam sub direktori \scp\:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    
    <?php
     
    /**
     * @author Masino Sinaga, http://www.openscriptsolution.com
     * @copyright October 11, 2009
     */
     
    require_once('../main.inc.php');
     
    ?>
     
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>osTicket:: SCP Login</title>
    <link rel="stylesheet" href="css/login.css" type="text/css" />
    <meta name="robots" content="noindex" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    </head>
     
    <body id="loginBody" onload="document.frmForgotPassword.email.focus()">
    <h1 id="logo"><a href="index.php">osTicket Staff Control Panel</a></h1>
    <div id="loginBox">
     
    <?php
     
    if($_GET && (!empty($_GET['key']) )) {
      $passwact=trim($_GET['key']);
     
      $sqlNewPass="SELECT username, email, new_passwd FROM ".STAFF_TABLE.
            " WHERE new_passwd_activate='".$passwact."'";
      $resNewPass=db_query($sqlNewPass);
      $countRec = db_num_rows($resNewPass);
     
      if ($countRec > 0) {
     
        while ($row = db_fetch_array($resNewPass)) {
          $real_new_password = $row['new_passwd'];
          $new_password = md5($row['new_passwd']);
          $user_email = $row['email'];
          $user_name = $row['username'];
        }
     
        // Change the password with the new one now, and don't forget to reset the key!
        $sql = "UPDATE ".STAFF_TABLE." SET passwd='".$new_password."', 
               new_passwd='', new_passwd_activate=''  
    	   WHERE email='".$user_email."'";
     
        if(db_query($sql) && db_affected_rows($res)){
     
          global $cfg;
          $helpdesk_email=$cfg->getDefaultEmail();
          $helpdesk_url=$cfg->getUrl();
          if($helpdesk_email){
            $helpdesk_email->send($user_email, 'New Password', ''.$user_name.', Your new password is: '.$real_new_password.'. Please login from '.$helpdesk_url.'scp/');
          }
     
          echo "<br /><b>$user_name</b>, <br />";
          echo "We have reset your password with the new one. You can now <a href='index.php'>login</a> with your new password that we have just sent to your email!<br /><br />";		
          echo '<div id="copyRights">Copyright &copy; <a href="http://www.osticket.com" target="_blank">osTicket.com</a></div>
                </body>
                </html>';
     
        } else {
     
          echo "<br />Failed when reset your password. Please try again later!<br />";
          echo '<div id="copyRights">Copyright &copy; <a href="http://www.osticket.com" target="_blank">osTicket.com</a></div>
                </body>
                </html>';
     
        }
     
      } else {
     
        echo "<br />Wrong activation key.<br /><br />";
        echo '<div id="copyRights">Copyright &copy; <a href="http://www.osticket.com" target="_blank">osTicket.com</a></div>
        </body>
        </html>';
     
      }
     
    }
     
    ?>

Itulah semuanya! Semoga dapat membantu.

Share

2,611 kali dibacaCetak Artikel Ini Cetak Artikel Ini

Komentar

  1. Gonzalo mengatakan:

    Hello, i see you know a lot about OST, and have seen your posts at the forum.
    There’s a problem lots of people are having with the last version, and it is that they(me included) can’t login as admin in a fresh install.

    I have checked every single possible solution in the support forum and nothing worked. Even tried this mod(i think is awesome!); it works perfect, but still even with the new password can’t login.

    Looks like the guys at the forum can’t find a solution to this problem, maybe you can help us with that.

    Thanks in advance.

  2. Masino Sinaga mengatakan:

    @Gonzalo

    Unfortunately, this never happened to me. I am not sure what is the causes of that problem. I tested osTicket on my localhost using Windows XP SP3 with Wamp server (Apache, MySQL, PHP included), and everything is worked fine here. I am so sorry I cannot help you much about the matter.

  3. rcmichelle mengatakan:

    you can search Password Genius from Google

Lacakbalik

  1. [...] Sinaga Leave a comment Go to comments For those of you who have implemented my MOD about Add Forgot Password Feature for HelpDesk Officer into osTicket v1.6 RC5 and need to force the helpdesk officer to change their password on the next login, here is the [...]

Utarakan pikiran Anda

*


*