Skip to content

Commit

Permalink
create login system backend and validations
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhimac111 committed Oct 18, 2022
1 parent aff1c2c commit f849c76
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions login_system/LogIn.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<title>Log in</title>
<link rel="stylesheet" type="text/css" href="Login.css">
<script language="javascript" type="text/javascript" src="validations.js">
</script>
</head>
<body>
Expand Down
51 changes: 51 additions & 0 deletions login_system/action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
//checking the connection
include "connection.php";

$username=$_REQUEST['uname'];
$password=$_REQUEST['pword'];
$empty=array();

//checking for empty inputs (php validations)
if(empty($username)) {array_push($empty,"empty username");}
if(empty($password)) {array_push($empty,"empty password");}

if(count($empty)==0) {

//getting encrypted password
$enc_pword= sha1($password);
//query for check users in database
$user_check="SELECT * FROM users WHERE username = '$username' AND password= '$enc_pword' LIMIT 1";
$result= mysqli_query($connection,$user_check);

if($result)
{
if(mysqli_num_rows($result)==1)
{
//if result == 1 row ,getting that raw to an array

//checking user or admin
$row=mysqli_fetch_assoc($result);
if($row['username']=="admin")
{
//creating a session
$_SESSION['username_logged']=$username;
header("location:../admin.php");//add your file path
}
else
{
$_SESSION['username_logged']=$username;
header("location:../home.php");//add your file path
}

}
else
{
header("location:LogIn.html");
}

}else {echo "<b>Error!!!!!</b><br>Can't Check users in database.......".$connection->error;}

}else {echo "<b>Username or Password empty.......</b>";}

?>
12 changes: 12 additions & 0 deletions login_system/connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
session_start();
?>
<?php
$host="localhost";
$username="root";
$password="";
$db="mydb"; //add your database name

$connection = mysqli_connect($host,$username,$password,$db) or die("Sorry!!! Can't Connect to the Database / Error is ".mysqli_connect_error());

?>
26 changes: 26 additions & 0 deletions login_system/validations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function validtext()
{

if((document.logform.uname.value.length<1)&&(document.logform.pword.value.length<1))
{
window.alert("Please enter your Username and Password");
return false;
}
else if(document.logform.uname.value.length<1)
{
window.alert("Username is Missing");
return false;
}
else if(document.logform.pword.value.length<1)
{
window.alert("Password is Missing");
return false;
}
if(document.logform.pword.value.length<7)
{
window.alert("Invalid Password (Password must contain atleast 6 characters)");
return false;
}


}

0 comments on commit f849c76

Please sign in to comment.