MyBB Community Forums

Full Version: Authenticating user, and returning usergroup
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok, basically, I need a little API, something to allow an application of mine to be able to authenticate logins. I made plugins like aggeeessss ago for MyBB, but not recently ^_^

I was thinking, send a JSON request, containing the username and password, then get a JSON response back containing the usergroup and a hash.

The hash would just be md5(username.password_hash), so the hash could be used instead of username/password (so it can be saved for future logins).


So the request would be like this:

[
	"action": "login",
	"type": "userpass",
	"username": "tom",
	"password": "password",
	"hash": ""
]

And the response would be:

[
	"username": "tom",
	"sessionHash": "fsfdifsjoidjiojioewre89uerw...",
	"usergroup": "4"
]

Basically, when I send json to mysite.com/api.php, i say "hey I want to validate this user, here's their username and password"

Then the server says "yup thats correct, here's a hash to use later instead"


So, the question is, how to I use the database in MyBB Toungue
You can use the core function validate_user_from_username($username, $password) to perform a full check and return the authenticated user (or an error instead). https://github.com/mybb/mybb/blob/master...er.php#L63

If you want to exchange data via JSON you will need to json_encode() the resulting array of the user's data.

You must include inc/functions_user.php before using it.
Thank you shade Smile

All sorted ^_^