Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login($username, $password){
- global $REQUIRED_USER_GROUP, $OVERRIDE_UID;
- if(!is_string($username) || !is_string($password)){
- print "Invalid username or password format";
- return false;
- }
- $user_details = posix_getpwnam($username);
- if($user_details === FALSE){
- print "User was not found";
- return false;
- }
- if(!is_int($user_details['uid'])){
- print "Invalid UID";
- return false;
- }
- if($user_details['uid'] !== $OVERRIDE_UID){
- // They don't have the override uid, check the group
- $required_user_group_info = posix_getgrnam($REQUIRED_USER_GROUP);
- if($required_user_group_info === FALSE){
- print "Could not get required group info";
- return false;
- }
- if(!in_array($username, $required_user_group_info['members'])){
- print "User '" . $username . "' not in the '" . $REQUIRED_USER_GROUP . "' group";
- return false;
- }
- }
- // If we get to here they are either uid matching OVERRIDE_UID or in the group REQUIRED_USER_GROUP
- if(pam_auth($username, $password, FALSE, FALSE) === TRUE){ // Check password only
- print "User and pass match unix";
- return true;
- }else{
- print "Could not match username and password";
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement