Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. function login($username, $password){
  2. global $REQUIRED_USER_GROUP, $OVERRIDE_UID;
  3. if(!is_string($username) || !is_string($password)){
  4. print "Invalid username or password format";
  5. return false;
  6. }
  7. $user_details = posix_getpwnam($username);
  8. if($user_details === FALSE){
  9. print "User was not found";
  10. return false;
  11. }
  12. if(!is_int($user_details['uid'])){
  13. print "Invalid UID";
  14. return false;
  15. }
  16. if($user_details['uid'] !== $OVERRIDE_UID){
  17. // They don't have the override uid, check the group
  18. $required_user_group_info = posix_getgrnam($REQUIRED_USER_GROUP);
  19. if($required_user_group_info === FALSE){
  20. print "Could not get required group info";
  21. return false;
  22. }
  23. if(!in_array($username, $required_user_group_info['members'])){
  24. print "User '" . $username . "' not in the '" . $REQUIRED_USER_GROUP . "' group";
  25. return false;
  26. }
  27. }
  28. // If we get to here they are either uid matching OVERRIDE_UID or in the group REQUIRED_USER_GROUP
  29. if(pam_auth($username, $password, FALSE, FALSE) === TRUE){ // Check password only
  30. print "User and pass match unix";
  31. return true;
  32. }else{
  33. print "Could not match username and password";
  34. return false;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement