Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*-------------SimpleBB.net--------------\
- | Project Start Date 02-February-2015; |
- | Project Developer Mike M; |
- | Project Type: Ebay Linking; |
- \--------------SimpleBB.net-------------*/
- class Account_Functions{
- function __Construct(){
- }
- /**
- * A method to generate randomized data [RDG | Random Data Generator] for example salting or session keys
- * @param integer $length DESCRIPTION: used to set a length that key should have
- * @param boolean $base64encode OPTIONAL DESCRIPTION: if true it will use base64_encode() on the return data
- * @param boolean $isSalt OPTIONAL DESCRIPTION: if true it will base64_encode() on the return data and will truncate the size to 22
- * @return string $value DESCRIPTION: returns the randomized data
- */
- function RDG($length, $base64encode = false, $isSalt = false){
- if(!is_integer($length)){
- trigger_error("RDG(): expects parameter 1 to be an integer, ".gettype($length)." given", E_USER_ERROR);
- }
- if(!is_bool($base64encode)){
- trigger_error("RDG(): expects parameter 2 to be a boolean, ".gettype($base64encode)." given", E_USER_ERROR);
- }
- if(!is_bool($isSalt)){
- trigger_error("RDG(): expects parameter 3 to be a boolean, ".gettype($base64encode)." given", E_USER_ERROR);
- }
- if($isSalt){
- $base64encode = true;
- }
- if(function_exists('mcrypt_create_iv')){
- $value = @mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
- if($value === ""){
- $value = @mcrypt_create_iv($length, MCRYPT_DEV_RANDOM);
- if($value === ""){
- trigger_error("MCRYPT_DEV_RANDOM and/or MCRYPT_DEV_URANDOM are/is not available", E_USER_ERROR);
- }
- }
- }else if(function_exists('openssl_random_pseudo_bytes')){
- $value = openssl_random_pseudo_bytes($length);
- if($value === ""){
- trigger_error("openssl_random_pseudo_bytes() is not available", E_USER_ERROR);
- }
- }else{
- trigger_error("mcrypt_create_iv() and openssl_random_pseudo_bytes() are not available", E_USER_ERROR);
- }
- if($base64encode){
- $value = rtrim(base64_encode($value), "=");
- $value = str_replace("+", ".", $value);
- }
- if($isSalt){
- $value = substr($value, 0, 22);
- if(strlen($value) <> 22){
- trigger_error("The salt length must be 22", E_USER_ERROR);;
- }
- }
- return $value;
- }
- function pw_hash($password, $cost = 12){
- if(!function_exists('crypt')){
- trigger_error("crypt() is not available", E_USER_ERROR);
- }
- if(!is_string($password)){
- trigger_error("pw_hash(): expects parameter 1 to be a string,", E_USER_ERROR);
- }
- if(!is_integer($cost)){
- trigger_error("pw_hash(): expects parameter 2 to be an integer, ".gettype($cost)." given", E_USER_ERROR);
- }
- if($cost < 9){
- trigger_error("pw_hash(): expects value of parameter 2 to be greater than 8, ".$cost." given", E_USER_ERROR);
- }
- if($cost < 9){
- trigger_error("pw_hash(): expects value of parameter 2 to be greater than 8, ".$cost." given", E_USER_ERROR);
- }
- if($cost > 31){
- trigger_error("pw_hash(): expects value of parameter 2 to be smaller than 32, ".$cost." given", E_USER_ERROR);
- }
- if(strlen($password) < 7 || empty($password)){
- trigger_error("pw_hash(): expects value of parameter 1 to be greater than 7".strlen($password)." characters given", E_USER_ERROR);
- }
- $salt = SELF::RDG(22, true, true);
- if(version_compare(phpversion(), '5.3.7', '<')){
- $salt = '$2a$'.$cost.'$'.$salt;
- }else{
- $salt = '$2y$'.$cost.'$'.$salt;
- }
- $hashed = crypt($password, $salt);
- if(strlen($hashed) <> 60){
- trigger_error("pw_hash(): Returned password is not valid", E_USER_ERROR);
- }
- return array("Password" => $hashed, "Salt" => $salt, "Cost" => $cost);
- }
- }
- for($i = 0; $i < 20; $i++){
- var_dump(Account_Functions::pw_hash("{insert_password#@$%+=_here.}"));
- echo("<hr />");
- }
- /*-------------SimpleBB.net--------------\
- | Project Start Date 02-February-2015; |
- | Project Developer Mike M; |
- | Project Type: Ebay Linking; |
- \--------------SimpleBB.net-------------*/
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement