Tuesday 4 September 2018

How to ensure that the php / html login form does not load values ​​in the User Name and Password fields

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
  }
?>

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.

0 comments:

Post a Comment