Skip to content

Commit

Permalink
Functional Custom Registration and Login System
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyfly2 committed Sep 18, 2019
1 parent ade9a4d commit b9bbdd4
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 52 deletions.
File renamed without changes.
26 changes: 18 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
<title>myLife - Login</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.css"/>
<link href="https://fonts.googleapis.com/css?family=Manjari&display=swap" rel="stylesheet">


</head>
<body style="background: #CFGD">
<body style="background-image: ">
<div class ="container">
<div class = "row">
<div class = "col-lg-6 m-auto">
<div class = "card bg-dark mt-5">
<div class="card-title bg-primary text-white mt-5">
<h3 class="text-center py-3">Login to myLife</h3>
<div class = "card bg-light mt-5">
<div class="card-title bg-success text-white mt-5">
<h3 class="text-center py-3" style="font-family: 'Manjari', sans-serif;">Login to myLife</h3>
</div>

<?php
Expand All @@ -27,15 +29,23 @@


<div class="card-body">
<form action="php/process.php" method="post">
<input type="text" name="UName" placeholder="Username" class="form-control mb-5">
<input type="password" name="Password" placeholder="Password" class="form-control mb-5">
<form action="php/login.php" method="post">
<input type="text" name="UName" placeholder="Username" class="form-control mb-4">
<input type="password" name="Password" placeholder="Password" class="form-control mb-4">
<button class="btn btn-success" name="Login">Login</button>
<br/>
<a href="pages/registration.php">Don't have an account? Sign up here</a>
</form>
</div>
</div>
</div>
</div>
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="js/jquery-3.3.1.slim.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="bootstrap-4.1.0/js/bootstrap.min.js"></script>
</body>
</html>
55 changes: 55 additions & 0 deletions pages/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>myLife - Register</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.css"/>
<link href="https://fonts.googleapis.com/css?family=Manjari&display=swap" rel="stylesheet">


</head>
<body>
<div class ="container">
<div class = "row">
<div class = "col-lg-6 m-auto">
<div class = "card bg-light mt-5">
<div class="card-title bg-success text-white mt-5">
<h3 class="text-center py-3" style="font-family: 'Manjari', sans-serif;">Register a myLife Account</h3>
</div>

<?php
if($_GET['Invalid'] == true)
{
?>
<div class="alert-light text-danger text-center py-3"><?php echo $_GET['Invalid']?></div>
<?php
}
?>


<div class="card-body">
<form action="../php/register.php" method="post">
<input type="text" name="firstname" placeholder="First Name" class="form-control mb-4">
<input type="text" name="lastname" placeholder="Last Name" class="form-control mb-4">
<input type="text" name="email" placeholder="Email" class="form-control mb-4">
<input type="text" name="UName" placeholder="Username" class="form-control mb-4">
<input type="password" name="Password" placeholder="Password" class="form-control mb-4">
<input type="password" name="ConfirmPassword" placeholder="Confirm Password" class="form-control mb-4">
<button class="btn btn-success" name="Register">Register</button>
<br/>
<a href="../index.php">Already have an account? Sign in here</a>
</form>
</div>
</div>
</div>
</div>
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="js/jquery-3.3.1.slim.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="bootstrap-4.1.0/js/bootstrap.min.js"></script>
</body>
</html>
52 changes: 52 additions & 0 deletions php/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
session_start();
require_once('config.php');
if(isset($_POST['Login']))
{
//Make user fills out all fields
if(empty($_POST['UName']) || empty($_POST['Password']))
{
header("location:../index.php?Invalid= Please Fill in the Required Fields");
}

//Assuming they use all fields, log them in
else
{
$username = $_POST['UName'];

$query = "SELECT UName FROM users WHERE UName='$username'";
$result = mysqli_query($link,$query);

if(!$result){
die('Error1: ' . mysqli_error($link));
}
$num = mysqli_num_rows($result);

//Verify that there is only one username
if($num==1){
$query2 = "SELECT firstname, lastname, UName, Password, email FROM users WHERE UName = '$username'";
$result2 = mysqli_query($link, $query2);
if(!$result2){
die('Error2: ' . mysqli_error($link));
}
list($first, $last, $userval, $passval, $email) = mysqli_fetch_array($result2);
$password = $_POST['Password'];
if(password_verify($password, $passval)){
$_SESSION['username'] = $userval;
$_SESSION['firstname'] = $first;
$_SESSION['lastname'] = $last;
$_SESSION['email'] = $email;
header("location:../pages/dashboard.php");
}
}
else{
header("location:../index.php?Invalid= Please Enter Correct Username or Password");
}
}
}
else
{
echo 'Not working now';
}

?>
32 changes: 0 additions & 32 deletions php/process.php

This file was deleted.

39 changes: 27 additions & 12 deletions php/register.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
<?php
session_start();
require_once('config.php');
if(isset($_POST['Login']))
if(isset($_POST['Register']))
{
if(empty($_POST['UName']) || empty($_POST['Password']))
//Catch if user doesn't fill out all data fields
if(empty($_POST['UName']) || empty($_POST['Password']) || empty($_POST['firstname']) || empty($_POST['lastname']) || empty($_POST['email']) || empty($_POST['ConfirmPassword']))
{
header("location:../index.php?Invalid= Please Fill in the Required Fields");
header("location:../pages/registration.php?Invalid= Please Fill in the Required Fields");
}

//Assuming all fields are filled out
else
{
$username = $_POST['UName'];
//Confirm passwords match
$password = $_POST['Password'];
$query = "SELECT FROM users WHERE UName='$username' AND Password='$password'";
$result = mysqli_query($link,$query);
if(mysqli_fetch_assoc($result)){
$_SESSION['username'] = $_POST['UName'];
header("location:../pages/dashboard.php");
$confirmpass = $_POST['ConfirmPassword'];

if($password!=$confirmpass){
header("location:../pages/registration.php?Invalid= Passwords did not match");
}
else{
header("location:../index.php?Invalid= Please Enter Correct Username or Password");
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$username = $_POST['UName'];

$password = password_hash($password, PASSWORD_DEFAULT);

$query = "INSERT INTO users (firstname, lastname, UName, Password, email) VALUES ('$firstname', '$lastname', '$username', '$password', '$email')";
$result = mysqli_query($link, $query);
if (!$result){
die('Error: ' . mysqli_error($link));
}
//Successfully Registered
else{
header("location:../index.php");
}
}
}


}
else
{
Expand Down

0 comments on commit b9bbdd4

Please sign in to comment.