Authentication registration and Secure login System using php
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); } }