- Impact
- 257
PHP:
Nod's Useful Scripts :)[/b]
Random Password Generator
[PHP]<?php
function cp($length=8,$use_upper=1,$use_lower=1,$use_number=1,$use_custom=""){
$upper = "ABCDEFGHJKLMNPQRSTUVWXYZ";
$lower = "abcdefghikmnopqrst";
$number = "2345679";
if($use_upper){
$seed_length += 26;
$seed .= $upper;
}
if($use_lower){
$seed_length += 26;
$seed .= $lower;
}
if($use_number){
$seed_length += 10;
$seed .= $number;
}
if($use_custom){
$seed_length +=strlen($use_custom);
$seed .= $use_custom;
}
for($x=1;$x<=$length;$x++){
$password .= $seed{rand(0,$seed_length-1)};
}
return($password);
}
echo cp();
//Will Print password like: wNFclGol
?>
-------------------------------------------
Replace Illegal Character with valid character function
PHP:
<?
$string= "Hi, I am a string!! and I need$to be $$$$$$$ stripped-s_s";
function sstring($ss,$e)
{
$sg = ereg_replace("[^A-Za-z0-9".$e."]", $e, $ss);
$sg = str_replace($e.$e.$e,$e,$sg);
$sg = str_replace($e.$e,$e,str_replace($e.$e,$e,$sg));
return $sg;
}
echo sstring($string,"_");
// First parameter is string, Second is character to replace illegal chars with
//will print Hi_I_am_a_string_and_I_need_be_stripped_s_s
?>
Rep and NP$ always welcome :tu:
------------------------------------------------
Auto Sanitize all GET and POST variables
PHP:
<?
function sanitize($var, $quotes = false) {
if (is_array($var)) { //run each array item through this function (by reference)
foreach ($var as &$val) {
$val = sanitize($val);
}
}
else if (is_string($var)) { //clean strings
$var = mysql_real_escape_string($var);
if ($quotes) {
$var = "'". $var ."'";
}
}
else if (is_null($var)) { //convert null variables to SQL NULL
$var = "NULL";
}
else if (is_bool($var)) { //convert boolean variables to binary boolean
$var = ($var) ? 1 : 0;
}
return $var;
}
$_GET=sanitize($_GET);
$_POST=sanitize($_POST);
?>
Last edited:






