mitrobill/system/autoload/Password.php

51 lines
1.3 KiB
PHP
Raw Normal View History

2017-03-11 02:51:06 +07:00
<?php
2021-11-08 19:56:30 +07:00
2017-03-11 02:51:06 +07:00
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2021-11-08 19:56:30 +07:00
**/
2017-03-11 02:51:06 +07:00
2021-11-08 19:56:30 +07:00
class Password
{
2017-03-11 02:51:06 +07:00
2021-11-08 19:56:30 +07:00
public static function _crypt($password)
{
return sha1($password);
2017-03-11 02:51:06 +07:00
}
2021-11-08 19:56:30 +07:00
public static function _verify($user_input, $hashed_password)
{
if (sha1($user_input) == $hashed_password) {
2017-03-11 02:51:06 +07:00
return true;
}
return false;
}
2021-11-08 19:56:30 +07:00
public static function _uverify($user_input, $hashed_password)
{
2017-03-11 02:51:06 +07:00
if ($user_input == $hashed_password) {
return true;
}
return false;
}
2021-11-08 19:56:30 +07:00
public static function _gen()
{
2017-03-11 02:51:06 +07:00
$pass = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#!123456789', 8)), 0, 8);
return $pass;
}
2024-08-07 11:10:43 +07:00
/**
* verify CHAP password
* @param string $realPassword
* @param string $CHAPassword
* @param string $CHAPChallenge
* @return bool
*/
public static function chap_verify($realPassword, $CHAPassword, $CHAPChallenge){
$CHAPassword = substr($CHAPassword, 2);
$chapid = substr($CHAPassword, 0, 2);
$result = hex2bin($chapid) . $realPassword . hex2bin(substr($CHAPChallenge, 2));
$response = $chapid . md5($result);
return ($response != $CHAPassword);
}
2021-11-08 19:56:30 +07:00
}