vishalonne
Technical User
- Jul 29, 2012
- 49
Dear All
I already have the php code for login and varification done using mysql database.
I have some links which should not work if user click them without VALID LOGIN.
My index.html page contain menu -
Home Computer Science Informatics Practices Take Test (login required) Software Register Get Together (login required)
Structure of my web site
index.html---- Login Box and Register Page Link
Computer Science (Menu)
XI (Sub Menu)
Unsolved Question Papers (Link) login not required
Project Samples (Link) login not required
Solved Materials (Link) login required
Forum (Link) login required
XI I (Sub Menu)
Unsolved Question Papers (Link) login not required
Project Samples (Link) login not required
Solved Materials (Link) login required
Forum (Link) login required
Here is the code - login.php (login form)
process_login.php (checking validity)
You can see the site which in development phase cbsecsnip
I already have the php code for login and varification done using mysql database.
I have some links which should not work if user click them without VALID LOGIN.
My index.html page contain menu -
Home Computer Science Informatics Practices Take Test (login required) Software Register Get Together (login required)
Structure of my web site
index.html---- Login Box and Register Page Link
Computer Science (Menu)
XI (Sub Menu)
Unsolved Question Papers (Link) login not required
Project Samples (Link) login not required
Solved Materials (Link) login required
Forum (Link) login required
XI I (Sub Menu)
Unsolved Question Papers (Link) login not required
Project Samples (Link) login not required
Solved Materials (Link) login required
Forum (Link) login required
Here is the code - login.php (login form)
PHP:
<script type="text/javascript" src="sha512.js"></script> // contain encryption code
<script type="text/javascript">
function formhash(form, password) {
// Create a new element input, this will be out hashed password field.
var p = document.createElement("input");
// Add the new element to our form.
p.name = "p";
p.type = "hidden"
p.value = hex_sha512(password.value);
// Make sure the plaintext password doesn't get sent.
password.value = "";
// Finally submit the form.
form.appendChild(p);
form.submit();
}
</script>
<?php
if(isset($_GET['error'])) {
echo 'Error Logging In!';
}
?>
</head>
<body><form action="process_login.php" method="post" name="login_form">
Email: <input type="text" name="email" /><br />
Password: <input type="password" name="password" id="password"/><br />
<input type="button" value="Login" onclick="formhash(this.form, this.form.password);" />
</form>
</body>
PHP:
<?php
define("HOST", "localhost"); // The host you want to connect to.
define("USER", "root"); // The database username.
define("PASSWORD", ""); // The database password.
define("DATABASE", "check1"); // The database name.
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
echo "Process Login";
include 'functions.php';
sec_session_start(); // Our custom secure way of starting a php session.
if(isset($_POST['email'], $_POST['p'])) {
$email = $_POST['email'];
$password = $_POST['p']; // The hashed password.
if(login($email, $password, $mysqli) == true) {
// Login success
echo 'Success: You have been logged in!';
} else {
// Login failed
header('Location: ./login.php?error=1');
}
} else {
// The correct POST variables were not sent to this page.
echo 'Invalid Request';
}
?>