-
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.
- Loading branch information
0 parents
commit f79f89a
Showing
7 changed files
with
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor/ | ||
.idea/ |
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,2 @@ | ||
# Auth | ||
### A basic PHP Authentication Package |
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,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" | ||
] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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); | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace MDP\Auth; | ||
|
||
interface Authenticatable | ||
{ | ||
|
||
} |
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,10 @@ | ||
<?php | ||
|
||
use MDP\Auth\Auth; | ||
|
||
if (!function_exists('auth')) { | ||
function auth(): Auth | ||
{ | ||
return new Auth(); | ||
} | ||
} |