Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# Simple_PHP_Auth
A Personal PHP Auth which you might find useful. Created for a Faster deployment of your Authentication Web App.
I Basically use it for simple login/Register and stuffs like that.

# How to Use

You can take hold of this lib by.

1. Starting up your terminal and punching

<code>$ git clone https://github.com/Kofacts/Simple_PHP_Auth.git </code>


2. Having done that, the package would be installed in a folder named "Simple_PHP_Auth"


3. Create a New instance of the login class which takes two params. Connection name and DB Name with table users_details.

<code> $login = new login($connect,"user_details");</code>

4. Having done that, You can verify a user by calling.

<code>$login->verifyLogin($_POST['username'],$_POST['password'],$callback_url,$error_message);</code>

5. You can also Check if the user is loggedin via:

<code>$login->isLoggedin();</code>


6. To register, you can use

<code>$login->register($username,$password,$email,$telephone,$address); in this order</code>

7. Once the user is loggedin, you can redirect the user using the "redirect($url) method";

</code>$login->redirect($url);</code>

Actually more features are still been added.

# I Saw a Bug..
Wheew. That's Awesome, Do send me a mail obodugorapheal[at]gmail.com

# Contribute?
DO Send me a pull request.

# How to Thank Me?
Just Star. Actually... Em, that's just it.



44 changes: 39 additions & 5 deletions src/Auth.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
<?php

//namespace Auth\dets;
//use src\Auth\login as k;
/** Once the user is logged in. **/
include "../src/login.php";

//$new = new k\login();
//var_dump(file_exists("../src/login.php"));
require_once("../src/login.php");
class Auth extends login{


class Auth{

public function __construct()
{
//The User must be logged in.
$this->isAlwaysLoggedin();



}

public static void user()
static function username()
{

//Use this method to echo the name of the guest.
echo $username;

}

static function email()
{
echo $email;
}

static function addr()
{
echo $address;
}

public function isAlwaysLoggedin()
{
//Check if the user is logged in else redirect.
if($this->isLoggedin()==TRUE)
{
return true;
}
else{
die("You Need to log in");
}
}
}
36 changes: 33 additions & 3 deletions src/login.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
//implenting Namespace.
namespace Auth\login;

/**
Project Name: Simple Login and Register Lib.
Expand All @@ -21,21 +23,30 @@ class login{
protected $errormessage1;
protected $errormessage2;

/**
* @param requires the connect and table Name.
*
**/
public function __construct($connect,$tablename)
{
//Empty Shit.
$this->connect=$connect;
$this->tablename=$tablename;
}

public function verifyLogin($username,$password,$callback,$errormessage1,$errormessage2)
/**
* @param needs the username, password, error message to display
* Error message can be encapsulated into HTML codes.
**/

public function verifyLogin($username,$password,$errormessage1,$errormessage2)
{
//Verify the user.

//Check the db first.
$this->username=$username;
$this->password=$password;
$this->callback-$callback;
//$this->callback=$callback;
$username1=$this->username;
$password1=$this->password;
$search1="SELECT * FROM $this->tablename WHERE username='$username1' AND password='$password1'";
Expand All @@ -50,7 +61,7 @@ public function verifyLogin($username,$password,$callback,$errormessage1,$errorm
session_start();
$_SESSION['username']=$this->username;
$_SESSION['password']=$this->password;
header("Location: $callback");
//Stores just the session.
ob_flush();
}
elseif(!$search11->num_rows>0)
Expand All @@ -73,6 +84,25 @@ public function verifyLogin($username,$password,$callback,$errormessage1,$errorm
}

}
public function redirect($url)
{
header("Location: $url");
}

public function isLoggedin()
{
//Once the user is logged in.

if($_SESSION['username']==$this->username && $_SESSION['password']==$this->password)
{
return true;
}
else{
return false;
}
}



public function logout()
{
Expand Down
20 changes: 17 additions & 3 deletions test/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
include "../src/login.php";
use Auth\login as l;
use Auth\dets as details;
require_once "../src/login.php";
require_once "../src/Auth.php";
try
{
$connect= new mysqli("localhost","root","pico4421","loginlib");
Expand All @@ -12,8 +15,19 @@
else{
if(isset($_POST['submit']))
{
$login= new login($connect,"user_details");
$login->verifyLogin($_POST['username'],$_POST['password'],"http://facebook.com","Failed Login","Error");
$login= new l\login($connect,"user_details");
//Logs the user in first.
$login->verifyLogin($_POST['username'],$_POST['password'],"Failed Login","Error");

if($login->isLoggedin()==TRUE)
{
//Checks when the user is loggedin in..
$auth= new details\Auth();
$auth::guest();
}
else{
$login->redirect("http://scholarsjoint.com");
}
//$login::guest();
}
}
Expand Down