When I type a password just log in, the a name means nothing. You can enter any name and be you log.But I also do not want to, I want that there is a specific name and password to login!
PHP:
<?php
// sha1() encrypted password
// the default is "test"
$password = '5df04db4e2ae413c40cb20359db92a925d6ff1b4';
// set username
$username = 'Marko';
// Start session
session_start();
// Initialize wrong password check variable
$isWrongPass = false;
// Initialize wrong name check variable
$isWrongUser = false;
if( !isset( $_SESSION['signedIn'] ) ) {
$_SESSION['signedIn'] = false;
}
// If the user clicked "sign out",
if( isset( $_GET['signout'] ) ) {
$_SESSION['signedIn'] = false;
// Change the location to where you want to redirect the user after signing out
header("Location: login.php");
}
// If the user submitted a password
if( isset( $_POST['password'] ) ) {
if ( sha1( $_POST['password'] ) == $password ) {
$_SESSION['signedIn'] = true;
} else {
$isWrongPass = true;
}
}
// If the user submitted a name
if ( $_POST['username'] == $username ) {
$_SESSION['signedIn'] = true;
} else {
$isWrongUser = true;
}
if( !$_SESSION['signedIn']):
?>
This method only works for a password, I tried to do the same for the name or fails.
HTML:
<?php if( $isWrongPass . $isWrongUser) { ?>
<div class="error">Pogresno ste uneli ime ili lozinku!</div>
<?php } ?>
<form id="signIn" method="post">
<label for="username">Ime</label>
<input style="border-radius: 100px" type="text" id="username" name="username" />
<label for="password">Lozinka</label>
<input style="border-radius: 100px" type="password" id="password" name="password" />
<input style="border-radius: 100px" type="submit" name="submit" class="submit" value="Uloguj Se" />
</form>