I have a hosting, where I got specified admin panel. On this panel I can set passwords and usernames, and the passwords get encrypted. So my question is: Is there any way for that to design the authentication?
I mean, when it requires login and password, it pops-up in browser, and I'd like to make this happen ON the website, where I can design it with CSS, not IN the browser. Any ideas?
Thanks in advance, any helpful answers gets me closer.
First, beware that the user name and password are sent in clear(base64 encoding) text if you are using "Basic Authentication" and not wrapped with the ssl module.
To achieve what you are trying do, you will have to use "form authentication":
<form method="post" action="validate_credentials.php" >
<table border="1" >
<tr>
<td><label for="user">Username</label></td>
<td><input type="text" name="user" id='user'></td>
</tr>
<tr>
<td><label for="pass" >Password</label></td>
<td><input name="pass" id='pass' type="password" ></input></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form>
and here is how the validate_credentials.php
file looks like:
<?php
// Grab User submitted information
$username = $_POST["user"];
$password = $_POST["pass"];
// Stored user name and password
$db_user = "secret_username";
$db_pass = "secret_password";
// Authentication mechanism
if ($username != $db_user and $password != $db_pass) {
echo"Invalid Credentials, Please try again.";
exit();
}
if ($username == $db_user and $password == $db_pass) {
echo"Valid Credentials, You are authenticated.";
// You can now serve the document that was requested.
}
I just tried to keep it simple so that you understand. To feel safe, validate user inputs and don't use clear text passwords in validate_credentials.php
file, you can google how to do that.