Home arrow PHP arrow Authentication Scripts for a User Management Application

Authentication Scripts for a User Management Application

In this article we will continue to discuss the application-wide scripts that we started to talk about in the last article. These special scripts are used by all the scripts and pages of the application. We will continue to look at the func.inc script that has several useful functions defined in it. This article is the third part of a nine-part series.

TABLE OF CONTENTS:
  1. Authentication Scripts for a User Management Application
  2. Script Explained
  3. Function Continued
  4. The logout script
By: David Web
Rating: starstarstarstarstar / 7
December 01, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The func.inc script

This script is essentially an include file that contains helper functions, such as the one that uses regular expressions to check if a given email address is correctly formatted. The file contains at least four functions, which are listed below:

<?php


function isadmin($id){

//run query to check if this user is admin

$sql = "SELECT level FROM users WHERE uid='".$id."'";

$res = mysql_query($sql);

if($res){

$row= mysql_fetch_assoc($res);

if($row['level'] == 'admin'){

return TRUE;

}else{

return FALSE;

}

}

}


function isAuthed($uname){

if(isset($uname)){

return TRUE;

}else{

return FALSE;

}


}


function genpass()

{

//This function generates a 7 letter password

$chars = "1234567890abcdefGHIJKLMNOPQRSTUVWxyz
ABCDEFghijklmnopqrstuvwXYZ1234567890";

$thepass = '';

for($i=0;$i<7;$i++)

{

$thepass .= $chars{rand() % 39};

}

return $thepass;

}



function checkEmail($email){

if(eregi('^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,8}$',$email)){

return TRUE;

}else{

return FALSE;

}

}

?>



 
 
>>> More PHP Articles          >>> More By David Web
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: