[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/class.functions.php, 1.1.2.1
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/class.functions.php, 1.1.2.1 |
Date: |
Sun, 23 May 2004 09:19:41 -0000 |
Update of /property
Added Files:
Branch: proposal-branch
class.functions.php
date: 2004/04/29 07:10:49; author: sigurdne; state: Exp; lines: +238 -0
Log Message:
db_addslashes
=====================================================================
<?php
/**************************************************************************\
* phpGroupWare - property
*
* http://www.phpgroupware.org
*
*
*
* Facilities Management
*
* Written by Sigurd Nes [sigurdne at online.no]
*
*
------------------------------------------------------------------------ *
* Copyright 2000 - 2003 Free Software Foundation, Inc
*
* This program is part of the GNU project, see http://www.gnu.org/
*
*
------------------------------------------------------------------------ *
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by the
*
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: class.functions.php,v 1.1.2.1 2004/04/29 07:10:49 sigurdne Exp
$ */
class property_functions
{
var $public_functions = array
(
'sanitize'=> True,
);
function property_functions()
{
$this->currentapp = 'property';
}
/**
* Escape strings before sending them to the database
*
* @param string $str the string to be escaped
* @return string escaped sting
*/
function db_addslashes($str)
{
if (!isset($str) || $str == '')
{
return '';
}
switch($GLOBALS['phpgw_data']['server']['db_type'])
{
case 'mssql':
return ereg_replace("'", "''", $str);
break;
case 'mysql':
return addslashes($str);
break;
case 'pgsql':
return addslashes($str);
break;
case 'sybase':
return str_replace("'", "''", $str);
break;
default:
return addslashes($str);
}
}
function sanitize($string,$type)
{
switch ($type)
{
case 'bool':
if ($string == 1 || $string == 0)
{
return True;
}
break;
case 'isprint':
$length = strlen($string);
$position = 0;
while ($length > $position)
{
$char = substr($string,
$position, 1);
if ($char < ' ' || $char > '~')
{
return False;
}
$position = $position + 1;
}
return True;
break;
case 'alpha':
if (preg_match("/^[a-z]+$/i", $string))
{
return True;
}
break;
case 'number':
if (preg_match("/^[0-9]+$/i", $string))
{
return True;
}
break;
case 'alphanumeric':
if (preg_match("/^[a-z0-9 -._]+$/i",
$string))
{
return True;
}
break;
case 'string':
if (preg_match("/^[a-z]+$/i", $string))
{
return True;
}
break;
case 'ip':
if
(eregi("^[0-9]{1,3}(\.[0-9]{1,3}){3}$",$string))
{
$octets = split('\.',$string);
for ($i=0; $i !=
count($octets); $i++)
{
if ($octets[$i] < 0 ||
$octets[$i] > 255)
{
return False;
}
}
return True;
}
return False;
break;
case 'file':
if
(preg_match("/^[a-z0-9_]+\.+[a-z]+$/i", $string))
{
return True;
}
break;
case 'email':
if
(eregi("^([[:alnum:]_%+=.-]+)@([[:alnum:]_.-]+)\.([a-z]{2,3}|[0-9]{1,3})$",$string))
{
return True;
}
break;
case 'password':
$password_length = strlen($string);
$password_numbers =
Array('0','1','2','3','4','5','6','7','8','9');
$password_special_chars = Array('
','~','`','!','@','#','$','%','^','&','*','(',')','_','+','-','=','{','}','|','[',']',"\\",':','"',';',"'",'<','>','?',',','.','/');
if(@isset($GLOBALS['phpgw_info']['server']['pass_min_length']) &&
is_int($GLOBALS['phpgw_info']['server']['pass_min_length']) &&
$GLOBALS['phpgw_info']['server']['pass_min_length'] > 1)
{
$min_length =
$GLOBALS['phpgw_info']['server']['pass_min_length'];
}
else
{
$min_length = 1;
}
if(@isset($GLOBALS['phpgw_info']['server']['pass_require_non_alpha']) &&
$GLOBALS['phpgw_info']['server']['pass_require_non_alpha'] == True)
{
$pass_verify_non_alpha = False;
}
else
{
$pass_verify_non_alpha = True;
}
if(@isset($GLOBALS['phpgw_info']['server']['pass_require_numbers']) &&
$GLOBALS['phpgw_info']['server']['pass_require_numbers'] == True)
{
$pass_verify_num = False;
}
else
{
$pass_verify_num = True;
}
if(@isset($GLOBALS['phpgw_info']['server']['pass_require_special_char']) &&
$GLOBALS['phpgw_info']['server']['pass_require_special_char'] == True)
{
$pass_verify_special_char =
False;
}
else
{
$pass_verify_special_char =
True;
}
if ($password_length >= $min_length)
{
for ($i=0; $i !=
$password_length; $i++)
{
$cur_test_string =
substr($string, $i, 1);
if
(in_array($cur_test_string, $password_numbers) || in_array($cur_test_string,
$password_special_chars))
{
$pass_verify_non_alpha = True;
if
(in_array($cur_test_string, $password_numbers))
{
$pass_verify_num = True;
}
elseif
(in_array($cur_test_string, $password_special_chars))
{
$pass_verify_special_char = True;
}
}
}
if ($pass_verify_num == False)
{
$GLOBALS['phpgw_info']['flags']['msgbox_data']['Password requires at least one
non-alpha character']=False;
}
if ($pass_verify_num == False)
{
$GLOBALS['phpgw_info']['flags']['msgbox_data']['Password requires at least one
numeric character']=False;
}
if ($pass_verify_special_char
== False)
{
$GLOBALS['phpgw_info']['flags']['msgbox_data']['Password requires at least one
special character (non-letter and non-number)']=False;
}
if ($pass_verify_num == True &&
$pass_verify_special_char == True)
{
return True;
}
return False;
}
$GLOBALS['phpgw_info']['flags']['msgbox_data']['Password must be at least
'.$min_length.' characters']=False;
return False;
break;
case 'any':
return True;
break;
default :
if
(isset($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['type']))
{
if
($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['type']($GLOBALS['phpgw_info']['server']['sanitize_types'][$type]['string'],
$string))
{
return True;
}
}
return False;
}
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/class.functions.php, 1.1.2.1,
nomail <=