Created
October 10, 2017 12:29
-
-
Save tallesairan/f2cbb585ab5424ebd8e32c1a0cb18976 to your computer and use it in GitHub Desktop.
Login on centos, using unix user and password on php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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