Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created October 10, 2017 12:29
Show Gist options
  • Save tallesairan/f2cbb585ab5424ebd8e32c1a0cb18976 to your computer and use it in GitHub Desktop.
Save tallesairan/f2cbb585ab5424ebd8e32c1a0cb18976 to your computer and use it in GitHub Desktop.
Login on centos, using unix user and password on php
<?php
class Login{
static function authenticate($user, $pass){
$shad = preg_split("/[$:]/",`cat /etc/shadow | grep "^$user\:"`);
$mkps = preg_split("/[$:]/",trim(`mkpasswd -m sha-512 $pass $shad[3]`));
return ($shad[4] == $mkps[3]);
}
public function handleAuth($user,$pass){
return $this->authenticate($user,$pass);
}
}
$login = new Login();
(bool) $login::handleAuth('user','pass');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment