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
https://forums.phpfreaks.com/topic/110437-solved-prevent-blank-password-creation/
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>

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.');
	}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.