2019-08-08 16:58:29 +03:00

45 lines
1.2 KiB
PHP

<?php
/**
* loginManager/lmUtils.php
* @desc utilities for correct functioning
* @version 1.0
* @author Fándly Gergő Zoltán
* @copy 2017 Fándly Gergő Zoltán
*/
class lmUtils{
/**
* generate a random string with special character
* @param int $length length of the requested string
* @return string
*/
public static function randomString($length){
$charset="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_-=+\?/.>,<";
$charsetLength=strlen($charset);
$string="";
for($i=0; $i<$length; $i++){
$string.=$charset[rand(0, $charsetLength-1)];
}
return $string;
}
/**
* validate google ReCaptcha
* @param string $secretkey secret key to captcha API
* @param string $response response of API
* @return bool
*/
public static function validateCaptcha($secretkey, $response){
$verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretkey."&response=".$response);
$data=json_decode($verify);
if($data->success){
return true;
}
else{
return false;
}
}
}
?>