Skip to content

Instantly share code, notes, and snippets.

@sunlee-newyork
Created November 16, 2013 21:33
Show Gist options
  • Select an option

  • Save sunlee-newyork/7505628 to your computer and use it in GitHub Desktop.

Select an option

Save sunlee-newyork/7505628 to your computer and use it in GitHub Desktop.
Website NONAME / LOGIN
<?php
session_start();
if (isset($_SESSION["user"])) {
header("Location: /IDEA/dashboard/index.php");
} elseif (isset($_SESSION["notvalid"])){
header("Location: /IDEA/activate/index.php");
}
?>
<html>
<head>
<style>
#title {
margin-top:100px;
font-family:HelveticaNeue-Light;
font-size:30px;
text-align:center;
}
#form {
width:300px;
margin-top:50px;
margin-left:auto;
margin-right:auto;
font-family:HelveticaNeue-Light;
}
#username, #password {
width:200px;
height:24px;
font-family:HelveticaNeue-Light;
font-size:14px;
}
#submit_button {
margin-top:20px;
font-size:20px;
}
#signup {
margin-left:95px;
font-family:HelveticaNeue-Light;
font-size:16px;
}
#search {
margin-left:5px;
font-family:HelveticaNeue-Light;
font-size:16px;
}
</style>
<title>LOGIN</title>
</head>
<body>
<?php require $_SERVER['DOCUMENT_ROOT']."/IDEA/header/index.php"; ?>
<div id="title">Login Here</div>
<div id="form">
<form action="index.php" name="form" method="post">
Username <input id="username" name="username" required/>
<br>
<br>
Password <input id="password" name="password" type="password" required/>
<br>
<br>
<input id="submit_button" type="submit" />
<a href="/IDEA/signup/index.php" id="signup">Sign Up</a>
<a href="/IDEA/search/index.php" id="search">Search</a>
</form>
</div>
</body>
</html>
<?php
// === PROCESS USER INPUT === \\
if ($_POST) {
// Request salt and iv
$sql = "SELECT * FROM `encryption` WHERE 1;";
$query = mysql_query($sql);
if (!$query) {
echo "ERRORRRRRR";
}
while ($row = mysql_fetch_assoc($query)) {
$salt = $row["salt"];
$iv = base64_decode($row["iv"]);
}
mysql_free_result($query);
// Get user input data
$username = $_POST["username"];
$password = $_POST["password"];
$encrypted_password = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $salt, $password, MCRYPT_MODE_CBC, $iv);
$encoded_password = base64_encode($encrypted_password);
// Match user input to DB
$sql = "SELECT * FROM `signup` WHERE `username` = '$username' AND `password` = '$encoded_password';";
$query = mysql_query($sql);
if (!$query) {
echo "something";
echo "<script>alert('Login information not found or is incorrect.');</script>";
die;
}
// If decrypted password is equal to user-supplied password, grant access
else {
while ($row = mysql_fetch_assoc($query)) {
echo "Username : " .$row["username"]. "</br>";
echo "Insecure Password : " .$password. "</br>";
if ($encoded_password === $row["password"]) {
if ($row["validate"] != 1) {
$_SESSION["notvalid"] = "Done";
echo "not validated";
} elseif ($row["validate"] = 1) {
$_SESSION["user"] = "Done";
echo "Login successful.";
}
}
}
}
// Wrap it up team
mysql_free_result($query);
echo "<script>location.reload();</script>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment