First, to make your password field look like a password you need to change its type to password instead of text, so type="text"
becomes type="password"
, you also need to add another password field and change its name so you could confirm it.
Login
<form align="center" method="post" action="index.php" >
Username:
<input type="text" name="username" />
<br/>
<br/>
Password:
<input type="password" name="password" />
<br/>
<br/>
Password (Confirmation):
<input type="password" name="password2" />
<br/>
<br/>
<input type="submit" value="Login" name="submit"/>
<input type="button" value="Register" onclick="document.location='registration.php'" />
</form>
Then at register, you need to grab the values sent in the request and compare them to each other(password and password2), if they're equal let the user continue, if they're not display an error message
<?PHP
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
if($password != $password2) die('Passwords do not match');
$file = file_get_contents("data.txt");
$string = "$username||$password";
if(!strstr($file, "$string"))
{
$myFile = "data.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "$username||$password\n";
fwrite($fh, $stringData);
print '<script> alert ("Registration Complete"); window.location="index.php"; </script>';
fclose($fh);
}
else
{
echo "Sorry the username: <b>$username</b> is already registered. Please use diferent username.";
}
}
?>