Matt
Matt

Reputation: 1131

Authenticate Laravel user without Laravel tools - connecting 2 programs

In a project we have a company CMS that resides in the public folder. It has it's own users and stuff for creating pages and other sorts of web items.

Now I have to hook the Laravel users table in that CMS, which would normally be fine. Except I can't verify a user seeing Laravel takes care of that somewhere(!) in the framework. And seeing the CMS is a large piece of coding that has been around for at least 10 years I'm not going to put that in routes, models and controllers.

So the simple solution is to just verify a user with password/username. But I cannot find any reference for user verification outside of Laravel.

So, my question is: How can I verify a user from the table users, that has been created by Laravel, against username/login from a program that is not loading Laravel.

Upvotes: 0

Views: 61

Answers (1)

Laurence
Laurence

Reputation: 60048

All you need to do is check if the username and password match, using bcrypt for the password hashing.

So as semi pseudocode (since I dont know what functions your CMS provides)

$username = $_POST['username'];

// Get the user record from your table
$user = $db->find->user($username);

if (password_verify($_POST['password'], $user->password))
{
     // login user
}
else
{
     // Wrong password
}

Upvotes: 1

Related Questions