User Management Code

  Home arrow User Management Code arrow random string generator (key generator...
USER MANAGEMENT CODE

random string generator (key generator)
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2003-04-15

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    This is a single function that returns a random string. Parameters allow you to specify length (min & max), use of caps/lowercase, use of numbers, and use of special characters. Example: email validation for user account creation (send the key to the email address entered and the user must supply it on the site to complete the process).

    By : mugane

    function str_makerand ($minlength, $maxlength, $useupper, $usespecial, $usenumbers)
    {
    /*
    Author: Peter Mugane Kionga-Kamau
    http://www.pmkmedia.com

    Description: string str_makerand(int $minlength, int $maxlength, bool $useupper, bool $usespecial, bool $usenumbers)
    returns a randomly generated string of length between $minlength and $maxlength inclusively.

    Notes:
    - If $useupper is true uppercase characters will be used; if false they will be excluded.
    - If $usespecial is true special characters will be used; if false they will be excluded.
    - If $usenumbers is true numerical characters will be used; if false they will be excluded.
    - If $minlength is equal to $maxlength a string of length $maxlength will be returned.
    - Not all special characters are included since they could cause parse errors with queries.

    Modify at will.
    */
    $charset = "abcdefghijklmnopqrstuvwxyz";
    if ($useupper) $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if ($usenumbers) $charset .= "0123456789";
    if ($usespecial) $charset .= "~@#$%^*()_+-={}|]["; // Note: using all special characters this reads: "~!@#$%^&*()_+`-={}|\\]?[\":;'><,./";
    if ($minlength > $maxlength) $length = mt_rand ($maxlength, $minlength);
    else $length = mt_rand ($minlength, $maxlength);
    for ($i=0; $i<$length; $i++) $key .= $charset[(mt_rand(0,(strlen($charset)-1)))];
    return $key;
    }
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More User Management Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    USER MANAGEMENT CODE ARTICLES

    - XCRYPT v1.0b
    - DB_eSession class stores sessions in a MySQL...
    - Ever Changing Dynamic Passcode Code
    - phpAutoMembersArea - create own members area
    - Azura Signup 2.5
    - Azura Signup 2.0
    - Azura Signup
    - Flexcustomer
    - PHP Quicksite 2.0
    - PHP Quicksite 1.0
    - random string generator (key generator)
    - Example Login system
    - Simple and Easy Security
    - Basic Security
    - UMA - User Management and Authentication

    Developer Shed Affiliates

     



    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap