forked from shamilkeheliya/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create login system backend and validations
- Loading branch information
1 parent
aff1c2c
commit f849c76
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>";} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |