Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * PROJECT CLEVERWEB GENERAL LESSER LICENSE INFORMATION v3.1
- * ------------------------------------------------------------
- * Copyright (C) 2011-2012 Nicholas Jordon
- * All rights reserved
- * Package: Project CleverWeb
- * http://ProjectCleverWeb.com
- *
- * License:
- * GNU LESSER GENERAL PUBLIC LICENSE VERSION 3
- *
- * This software is free software: you can redistribute it
- * and/or modify it under the terms of the GNU Lesser
- * General Public License as published by the Free Software
- * Foundation, version 3 of the License, You may not use this
- * software except in compliance with the license.
- *
- * You may obtain a copy of the license at:
- * http://www.gnu.org/licenses/lgpl-3.0.html
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the license is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.
- *
- * Verfication Key: e450edcbe7703e40d9edcf19a18fb4bc
- */
- function cw_randchar($length=NULL,$case=NULL,$spaces=NULL) {
- // Removes "," chars if it is a number
- if(!is_numeric($length)){
- $temp_length = $length;
- if(strstr($length,",")){
- $length = preg_replace("/[,]*/","",$length);
- if(!is_numeric($length)){
- $length = strlen($temp_length);
- }
- }
- elseif(!is_numeric($length)){
- $length = strlen($length);
- }
- }
- if($length==NULL||$length==0){
- // Best password length
- $length = 8;
- }
- // 2000 seems enough?
- if($length>2000){
- $length = 2000;
- }
- // numbers done twice so their % chance stays the same
- $characters = "0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $length = ceil($length);
- if(stristr($case,"lower")){
- $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
- $case = true;
- }
- if(stristr($case,"upper")){
- $characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $case = true;
- }
- if($spaces==true){
- // 8 spaces to make it seem more like encrypted words
- $characters .= " ";
- if(!$case==true){
- // 8 more if both capital and lower-case letters
- $characters .= " ";
- }
- }
- if(!is_bool($spaces)){
- // return error msg
- /**
- * NOTE: the error class, function and/or message is not published
- * in this function but is respectfully included as part of this
- * function as an "intellectual" object under CleverWeb's license.
- */
- }
- // this part is done oddly due to it will otherwise error.
- // it kept being one char place short randomly however not consistantly.
- for ($count = 1; ; $count++) {
- if (strlen($string)==$length) {
- break;
- }
- $string .= $characters[mt_rand(0, strlen($characters))];
- }
- return $string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement