Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

Authentication registration and Secure login System using php

July 6, 2018 Pakainfo Programming, Mysql, Mysqli, php Leave a comment

Authentication registration and Secure login System using php

Contents

  • Authentication registration and Secure login System using php
    • Create a table
    • Db Connectivity
    • form_register
    • login_form
    • Logout
    • clientname Check
    • Registration Form
    • get Details
    • login_form Form HTML part
    • PHP part
    • Related posts

Welcome on Pakainfo.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Authentication registration and Secure login System using php

In this post we will show you Best way to implement How to Create a Secure Login Script in PHP and MySQL, hear for How to Create MySQL Injection free Secure Login System in PHP with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Create a table

CREATE TABLE IF NOT EXISTS `liveemployees` (
  	`id` int(10) NOT NULL AUTO_INCREMENT,
  	`first_name` varchar(100) NOT NULL,
  	`email` varchar(100) NOT NULL,
  	`clientname` varchar(100) NOT NULL,
  	`your_secpass` varchar(100) NOT NULL,
  	PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

Db Connectivity

require_once("../config.php"); 
 	global $db;

 	$db = mysqli_connect(DBHOST, DBemployee, DBsecpass, DBNAME);
 	if(!$db){
      	 	die( "Sorry!  your There seems to be some a problem connecting db to our database.");
 	}

form_register

function form_register($first_name, $employee, $secpass, $emailId){
  	 	global $db; 
  	 	$first_name = mysqli_real_escape_string($db, $first_name);
   	 	$clientname = mysqli_real_escape_string($db, $employee);
   	 	$your_secpass = mysqli_real_escape_string($db, $secpass);
   	 	$email = mysqli_real_escape_string($db, $emailId);
  	 	$wp_hasher = new your_secpassHash(16, true);
 	 	$secpass = $wp_hasher->Hashyour_secpass( trim( $your_secpass ) );
 
  	 	$sql = "INSERT INTO liveemployees (first_name, email,your_secpass,clientname) VALUES ('".$first_name."', '".$email."', '".$secpass."', '".$clientname."') "; 
  	 	$result = mysqli_query($db, $sql);
  	 	return mysqli_insert_id($db);
 	}

login_form

function login_form($employee, $secpass){
  	global $db; 
  	$clientname = mysqli_real_escape_string($db, $employee);
   	$your_secpass = mysqli_real_escape_string($db, $secpass);
  	$sql = "SELECT id, your_secpass FROM liveemployees WHERE clientname='".$clientname."' LIMIT 1 "; 
  	$result = mysqli_query($db, $sql);
  	$id = mysqli_fetch_row($result);
 	 if($id){
  	 	$your_secpass_hashed = $id[1];
 	 	 $wp_hasher = new your_secpassHash(16, true);
 	 	 if($wp_hasher->Checkyour_secpass($your_secpass, $your_secpass_hashed)) {
  	 	 	return $id[0];
  	 	}
  	} else {
  	 	return false;
  	}
}

Logout

function logout(){
 unset($_SESSION['employee_id']);
 session_destroy(); 
 header('Location: index.php');
 exit();
}

clientname Check

function clientnameExist($employee){
   	global $db; 
  	$clientname = mysqli_real_escape_string($db, $employee);
   	$sql = "SELECT id FROM liveemployees WHERE clientname='".$clientname."' LIMIT 1 "; 
  	$result = mysqli_query($db, $sql);
  	 $id = mysqli_fetch_row($result);
   	return ($id[0] > 0);
 }
}

Registration Form

<form action="" method="post" >
 <?php if(!empty($reg_errors)) {
 echo '<div class="error">';
 foreach ($form_register_errors as $error) {
 echo '<p>'.$error.'</p>';
 }
 echo '</div>';
 } ?>
 <div class="group">
 <input type="text" name="first_name" ><p class="cust_fency"></p><p class="bar"></p>
 <label>Full name</label>
 </div>
 <div class="group">
 <input type="email" name="email" ><p class="cust_fency"></p><p class="bar"></p>
 <label>Email</label>
 </div>
 <div class="group">
 <input type="text" name="clientname" ><p class="cust_fency"></p><p class="bar"></p>
 <label>clientname</label>
 </div>
 <div class="group">
 <input type="text" name="your_secpass" ><p class="cust_fency"></p><p class="bar"></p>
 <label>your_secpass</label>
 </div>
 <input type="hidden" name="form_register" value="yes" > 
 <button type="submit" class="buttonui "> <p> form_register </p>
 <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div>
 </button>  
 <a class="buttonui " href="login_form.php?action=login_form" style="line-height:4em; text-decoration: none; padding:2%" > <p> login_form Back </p> <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div></a>
  </form>

get Details

$form_register_errors= $simple_login_form_er = array();
if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['form_register'])) {
 $fields = array(
 'first_name',
 'clientname',
 'email',
 'your_secpass'
 );
 foreach ($fields as $field) {
 if (isset($_POST[$field])) $posted[$field] = stripslashes(trim($_POST[$field])); else $posted[$field] = '';
 }
 if ($posted['first_name'] == null)
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee first_name.', 'pakainfo'));
 if ($posted['email'] == null)
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee Email.', 'pakainfo'));
 if ($posted['your_secpass'] == null)
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee your_secpass.', 'pakainfo'));
 if ($posted['clientname'] == null )
 array_push($form_register_errors, sprintf('<b>Notice</b>: Please enter the employee clientname.', 'pakainfo'));
 if(clientnameExist($posted['clientname'])){
 array_push($form_register_errors, sprintf('<b>Notice</b>: The Entered clientname Already Exist.', 'pakainfo'));
 }
 $reg_errors = array_filter($form_register_errors);
 if (empty($reg_errors)) { //Check whether simple everything entered to new create new employee.
 form_register($posted['first_name'], $posted['clientname'], $posted['your_secpass'], $posted['email']); 
 } 
}

login_form Form HTML part

<form action="" method="post" >
 <?php if(!empty($log_error) || (isset($mismatchErr) && $mismatchErr != '')) {
 echo '<div class="error">';
 foreach ($simple_login_form_er as $error) {
 echo '<p>'.$error.'</p>';
 } 
 echo $mismatchErr.'</div>';
 } ?>
 <div class="group">
 <input type="text" class="used" name="clientname" ><p class="cust_fency"></p><p class="bar"></p>
 <label>clientname</label>
 </div>
 <div class="group">
 <input type="your_secpass" name="your_secpass" ><p class="cust_fency"></p><p class="bar"></p>
 <label>your_secpass</label>
 </div>
 <input type="hidden" name="login_form" value="yes" >
 <button type="submit" class="buttonui "> <p> login_form </p>
 <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div>
 </button> 
 <a class="buttonui " href="login_form.php?action=form_register" style="line-height:4em; text-decoration: none; padding:2%" > <p> form_register </p> <div class="ripples buttonRipples"><p class="ripplesCircle"></p></div></a>
 </form>

PHP part

if('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['login_form'])) { 
 $clientname = stripslashes(trim($_POST['clientname']));
 $your_secpass = stripslashes(trim($_POST['your_secpass']));
 $mismatchErr = '';
 if ($your_secpass == null )
 array_push($simple_login_form_er, sprintf('<b>Notice</b>: Please enter the employee your_secpass.', 'pakainfo'));
 if ($clientname == null )
 array_push($simple_login_form_er, sprintf('<b>Notice</b>: Please enter the employee clientname.', 'pakainfo'));
 $log_error = array_filter($simple_login_form_er);
 if (empty($log_error)) { //Check whether all the everything entered to create new employee.
 $login_formn = login_form($clientname, $your_secpass);
 if($login_formn){
 $_SESSION['employee_id'] = $login_formn;
 header('Location: index.php');
 exit();
 }else {
 $mismatchErr .= sprintf('<p> <b>Notice</b>: Please simple enter Valid Credentials. </p>', 'pakainfo'); 
 }
 }
}

Example

Also Read This ๐Ÿ‘‰   Laravel 5.8 active menu item using request

I hope you have Got How to Create a Secure Login Script in PHP and MySQL And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Related posts:

  1. jQuery Ajax Secure Login Registration System in PHP and MySQL
  2. Secure Login System with PHP and MySQLi – login page in php
  3. Create a Registration and Login System with PHP and MySQL
  4. Nodejs Login and Registration with PHP MySQL and SQLite Example
advanced security - php register/login systemcomplete login system php mysqlhow to create a secure login script in php and mysqlphp login system with admin featuresphp secure login frameworkphp secure login script 2019php secure login script downloadphp secure login script free

Post navigation

Previous Post:Calculate get Time difference between two dates using PHP
Next Post:Insert Update Delete using PHP and mysql for Frontaccounting – crud

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

Weโ€™re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (93) Education (63) Entertainment (130) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2345) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (147) Technology (2416) Tips and Tricks (130) Tools (214) Top10 (505) Trading (94) Trending (76) VueJs (250) Web Technology (112) webtools (200) wordpress (166) World (343)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

ยฉ 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites