Jump to content

[SOLVED] Prevent blank password creation


MadnessRed

Recommended Posts

OK, firefox has a useful feature of putting in your password for sites. however it is being very unhelpful in this instance.

 

I have an options page, here the user can do many thing including changing the password.

 

There are 3 boxes

 

Old Password

New password

Retype

 

by default Firefox fills in the Old password field but leaves the others blank blank which means every time you make a change, if you forget to remove the password from the Old password field, it gets deleted. I would like to know weather doing this would fix that

 

Old Code

	if (isset($_POST["db_password"]) && md5($_POST["db_password"]) == $user["password"]) {

	if ($_POST["newpass1"] == $_POST["newpass2"]) {

		$newpass = md5($_POST["newpass1"]);

		doquery("UPDATE {{table}} SET `password` = '{$newpass}' WHERE `id` = '{$user['id']}' LIMIT 1", "users");

		setcookie(COOKIE_NAME, "", time()-100000, "/", "", 0); //le da el expire

		message($lang['succeful_changepass'], $lang['changue_pass']);

	}

 

 

New Code

	if (isset($_POST["db_password"]) && md5($_POST["db_password"]) == $user["password"]) {

	if ($_POST["newpass1"] == $_POST["newpass2"]) {
	if ($_POST["newpass1"] != "") {

		$newpass = md5($_POST["newpass1"]);

		doquery("UPDATE {{table}} SET `password` = '{$newpass}' WHERE `id` = '{$user['id']}' LIMIT 1", "users");

		setcookie(COOKIE_NAME, "", time()-100000, "/", "", 0); //le da el expire

		message($lang['succeful_changepass'], $lang['changue_pass']);

	}}

Link to comment
Share on other sites

Here's what I do on my sites for that particular instance...

 

<script language="javascript" type="text/javascript">
<!--
function checkPassword(form) {
    if (form.password.value == '')
    {                               
        alert('You must supply a Password.');
        form.password.focus();
        return false;
    } 
    if (form.password.value != form.password_rpt.value)
    {                         
        alert('The Repeat Password did not match the Password.');
        form.password_rpt.focus();
        return false;
    }
// -->
</script>


<form name="test_form" action="" method="POST" onSubmit="return checkPassword(this)">
<input type="text" name="password">
<input type="text" name="password_rpt">
<input type="submit" name="submit_button" value="Test Me">
</form>

Link to comment
Share on other sites

ok thanks woudl this work then

 

	if (isset($_POST["db_password"]) && md5($_POST["db_password"]) == $user["password"]) {

	if ($_POST["newpass1"] == $_POST["newpass2"]) {
		if ($_POST["newpass1"] != "") {
			$newpass = md5($_POST["newpass1"]);
			doquery("UPDATE {{table}} SET `password` = '{$newpass}' WHERE `id` = '{$user['id']}' LIMIT 1", "users");
			setcookie(COOKIE_NAME, "", time()-100000, "/", "", 0); //le da el expire
			message($lang['succeful_changepass'], $lang['changue_pass']);
		}
	} else {
			alert('The Repeat Password did not match the Password.');
	}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.