Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosdipaoloSV committed Jan 9, 2021
0 parents commit f79f89a
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
.idea/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auth
### A basic PHP Authentication Package
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "marcosdipaolo/auth",
"type": "library",
"description": "An PHP Authentication Package",
"authors": [
{
"name": "Marcos Di Paolo",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.2",
"marcosdipaolo/session": "^1.0"
},
"autoload": {
"psr-4": {
"MDP\\Auth\\": "src/"
},
"files": [
"src/helpers.php"
]
}
}
66 changes: 66 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace MDP\Auth;

class Auth
{
/**
* @param string $password
* @return false|string|null
*/
public function hash(string $password)
{
return password_hash($password, PASSWORD_BCRYPT);
}

public function user()
{
return session()->get('user');
}

public function login(Authenticatable $user)
{
session()->put('user', $user);
}

public function logout()
{
session()->forget('user');
}

public function isUserLoggedIn()
{
return session()->has('user') && (session()->get('user') instanceof Authenticatable);
}
}
8 changes: 8 additions & 0 deletions src/Authenticatable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace MDP\Auth;

interface Authenticatable
{

}
10 changes: 10 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use MDP\Auth\Auth;

if (!function_exists('auth')) {
function auth(): Auth
{
return new Auth();
}
}

0 comments on commit f79f89a

Please sign in to comment.