Author Topic: Enable users to change the password by themselves  (Read 2634 times)

0 Members and 1 Guest are viewing this topic.

Offline luca69

  • Occasional poster
  • *
  • Posts: 95
    • View Profile
Enable users to change the password by themselves
« on: January 27, 2009, 05:15:06 PM »
I played a little bit with the admin panel and I found useful for the users to have the possibility to change the password by themselves.

This is my code:
Code: [Select]
[changepass]
{.if | %user% |
<html>
<head>
<title>Pass Changer</title>
</head>
<body>
<b><font size="4"> Welcome %user% ! </b>
<p>
<br><font size="4"> Then type the new password and click on Change. Leave it blanck to remove the password.
<p>
<form method=post action="/~userpasschange">
  <table>
  <tr><td align=left><b><font size="4"><font size="4">New Password</font></b></font></b><td><b><font size="4">: &nbsp;</font></b><span style="background-color: #000000"><input name=pass type=password style="font-size:10pt; font-weight:bold; border:1px solid #88f" size="20" ></span>
  <tr><td align=left><font size="4">Click <a href="/">here</a> to return to HOME.</font><td align=center><input type=submit value="Change">
  </tr></table>
</form>

</body>
</html>
|{.section|usererror.}.}

[userpasschange]
{.if | %user% |
<html>
<head>
<title>Pass Changer</title>
</head>
<body>
{.set account|%user%|password={.postvar|pass.}.}
<p><font size="4">Password changed!</font></p>
<p>Click <a href="/">here</a> to return to HOME.</p>
</body>
</html>
|{.section|usererror.}.}

[usererror]
<html>
<head>
<title>Error</title>
</head>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center"><font size="6"><b>You must login before chaning the password.</b></font></p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p>Click <a href="/">here</a> to return to HOME.</p>
</body>
</html>

To have the menu entry, you have to modify the current template and add the second line in the following peace of code:
Code: [Select]
{.if not| %user%                             | <li><a href="~login"><img src="/~img27"> Login</a></li> .}

{.if | %user%                                | <li><a href="/~changepass"> Change password</a></li> .}

{.if| {.get|can upload.}                     | <li><a href="~upload"><img src="/~img32"> Upload</a></li> .}
{.if| {.and | {.get|can archive.} | {.not|{.?search.}.} .}



Open: I think it is a good idea to ask the user twice for the new password and check if the two entry match; if not the user shall be prompt for the new password again.
« Last Edit: January 27, 2009, 05:17:20 PM by luca69 »
Life is what happens to you while you are busy making other plans

Offline Unknown8063

  • Occasional poster
  • *
  • Posts: 96
    • View Profile
Re: Enable users to change the password by themselves
« Reply #1 on: January 27, 2009, 06:52:20 PM »
Ooo this is a very nice idea and I think I'll give it a test run when I get home.  Thanks for sharing.

Offline luca69

  • Occasional poster
  • *
  • Posts: 95
    • View Profile
Re: Enable users to change the password by themselves
« Reply #2 on: January 27, 2009, 08:46:58 PM »
Ooo this is a very nice idea and I think I'll give it a test run when I get home.  Thanks for sharing.

Let me know what you think about it. Hints are welcome  ;)
Life is what happens to you while you are busy making other plans

Offline luca69

  • Occasional poster
  • *
  • Posts: 95
    • View Profile
Re: Enable users to change the password by themselves
« Reply #3 on: February 04, 2009, 02:40:52 PM »
have a look at

http://www.rejetto.com/forum/index.php?topic=6590


uhm I checked the latest version and I found:

Code: [Select]
{.if|{.^allow password.}  | <li><a href="/~error">Change Password</a></li> .}
This means that every time a user tries to change the password he/she gets an error!

I'll change the code and I'll make it compatible with 211 (new macro names!)
« Last Edit: August 15, 2009, 03:54:47 PM by Mars »
Life is what happens to you while you are busy making other plans

Offline r][m

  • Tireless poster
  • ****
  • Posts: 347
    • View Profile
Re: Enable users to change the password by themselves
« Reply #4 on: February 05, 2009, 04:37:17 PM »
luca69
Quote
Let me know what you think about it. Hints are welcome
Thanks for sharing, works fine in default tpl, here. Very useful  :)

Offline luca69

  • Occasional poster
  • *
  • Posts: 95
    • View Profile
Re: Enable users to change the password by themselves
« Reply #5 on: February 06, 2009, 04:01:02 PM »
Update: now the code ask for password twice and if there is a mismatch the user is prompt to enter the new password again.

Code: [Select]
[changepass]
{.if | %user% |
<html>
<head>
<title>Pass Changer</title>
<script type="text/javascript">
function validatePassword(form){
if (form.pass1.value != form.pass2.value){
alert("Password do not match: please enter again.");
return false;
  }
 return true;
}
</script>

</head>
<body>
<b><font size="4"> Welcome %user% ! </b>
<p>
<br><font size="4"> Then type the new password and click on Change. Leave it empty to remove the password.
<p>
<form method=post action="/~userpasschange" onsubmit="return validatePassword(this);">
  <table>
  <tr><td align=left><b><font size="4"><font size="4">New Password</font></b></font></b><td><b><font size="4">: &nbsp;</font></b><span style="background-color: #000000"><input name=pass1 type=password style="font-size:10pt; font-weight:bold; border:1px solid #88f" size="20" ></span>
  <tr><td align=left><b><font size="4"><font size="4">Type Password again</font></b></font></b><td><b><font size="4">: &nbsp;</font></b><span style="background-color: #000000"><input name=pass2 type=password style="font-size:10pt; font-weight:bold; border:1px solid #88f" size="20" ></span>
  <tr><td align=left><font size="4">Click <a href="/">here</a> to return to HOME.</font><td align=center><input type=submit value="Change" >
  </tr></table>
</form>

</body>
</html>
|{.section|usererror.}.}

[userpasschange]
{.if |%user%|
<html>
<head>
<title>Pass Changer</title>
</head>
<body>
{.set account|%user%|password={.postvar|pass1.}.}
<p><font size="4">Password changed!</font></p>
<p>Click <a href="/">here</a> to return to HOME.</p>
</body>
</html>
|{.section|usererror.}.}


[usererror]
<html>
<head>
<title>Error</title>
</head>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center"><font size="6"><b>You must login before chaning the password.</b></font></p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p>Click <a href="/">here</a> to return to HOME.</p>
</body>
</html>

Life is what happens to you while you are busy making other plans