-3

I have written this simple php code (see below). The problem is that when i try running this code, the form loads values into both the username and password input fields. I have tried setting autocomplete = "off" in both the form tag and the input tag as suggested here but it does not seem to work. My browser if firefox 38.0 for Ubuntu canonical 1.0. What is the problem here?

<?php

if (isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])){echo "yesu";
  $username = $_POST['username']; 
  $password = md5 ($_POST['password'] . 'ijdb');
  print "welcome $username";
/*header ('Location: .');
exit();*/

  }
    else{
?>
<form action = "" method = "post" autocomplete = "off">
Username: <input type = "text" name = "username" autocomplete = "off"/><p>
Password: <input type = "password" name = "password" autocomplete = "off"/><p>
<input type = "submit" name = "submit" value = "login"/>
<form>
<?php
  }
?>
Community
  • 1
  • 1
Maina Mailu
  • 73
  • 3
  • 13

4 Answers4

2

Put a hidden empty text field between username and password

<input type="text" name="username">
<input type="text" style="display:none">// like this 
<input type="password" style="display:none">// Introducing this line ensures that whenever you load the form the password field is blank
<input type="password" name="password">

Explain

It will make the username text field not to show any previously typed words in a drop down. Since there is no attribute like name, id for the input field it wouldn't send any extra parameters also.

Maina Mailu
  • 73
  • 3
  • 13
Saty
  • 21,683
  • 7
  • 29
  • 47
0

Use placeholders

Username: <input type = "text" name = "username" placeholder = "username"/>
Password: <input type = "password" name = "password" placeholder = "password"/>
Babar
  • 896
  • 2
  • 11
  • 29
0

seems like some preset in your browser(check addons or whatever), anyway if you wish to get rid of it - just use custom names for inputs, aka:

Username: <input type = "text" name = "uname" autocomplete = "off"/>

or

Username: <input type = "text" name = "something_unusual" autocomplete = "off"/>`
Dmytro
  • 114
  • 4
0

There are three things you can try:

<form autocomplete="off">

Ensure that when you are using autocomplete="off" that you an html5 declaration:

<!DOCTYPE html>

Lastly, it might also be browser settings remembers especially passwords and username combinations

Conrad Lotz
  • 7,324
  • 3
  • 21
  • 26