Miscellaneous Code
  Home arrow Miscellaneous Code arrow Random Password Generator
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

Random Password Generator
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2007-02-05

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Generates random password for a selected length from a selected set (numbers, lowercase, uppercase, lower+upper, lower+upper+numbers, almost full keyboard).

    By : bjpalmer

    <?php

    //Random Password Function
    function generatePassword ($passwordLength, $characterSet)
    {
    //Random password generator if anyone needs one
    //B Palmer 2007 - Distribute, manipulate, just dont sell, not that its worth anything anyway!

    //Character Sets
    //1 - numbers only (48[0] to 57[9]) - 10
    //2 - lowercase only (97[a] to 122[z]) - 26
    //3 - uppercase only (65[A] to 90[Z]) - 26
    //4 - lowercase (97[a] to 122[z]) + uppercase (65[A] to 90[Z]) - 52
    //5 - lowercase (97[a] to 122[z]) + uppercase (65[A] to 90[Z]) + numbers (48[0] to 57[9]) - 62
    //6 - full keyboard set (32 to 126) less space (32[space], 34["], 39['], 96[`]) - 91


    //1 - numbers only (48[0] to 57[9]) - 10
    if($characterSet==1)
    {
    $passwordString = "";
    for($i=0; $i<$passwordLength; $i++)
    {
    $selectedChar = rand(0, 9);
    $passwordString .= $selectedChar;
    }
    }

    //2 - lowercase only (97[a] to 122[z]) - 26
    if($characterSet==2)
    {
    $passwordString = "";
    for($i=0; $i<$passwordLength; $i++)
    {
    $selectedChar = rand(97, 122);
    $selectedChar = chr($selectedChar);
    $passwordString .= $selectedChar;
    }
    }

    //3 - uppercase only (65[A] to 90[Z]) - 26
    if($characterSet==3)
    {
    $passwordString = "";
    for($i=0; $i<$passwordLength; $i++)
    {
    $selectedChar = rand(65, 90);
    $selectedChar = chr($selectedChar);
    $passwordString .= $selectedChar;
    }
    }

    //4 - lowercase (97[a] to 122[z]) + uppercase (65[A] to 90[Z]) - 52
    if($characterSet==4)
    {
    $passwordString = "";
    for($i=0; $i<$passwordLength; $i++)
    {
    $selectedChar = rand(1, 52);
    if($selectedChar>=1&&$selectedChar<=26)
    {
    $selectedChar = $selectedChar + 64;
    $selectedChar = chr($selectedChar);
    }
    else
    {
    $selectedChar = $selectedChar + 70;
    $selectedChar = chr($selectedChar);
    }
    $passwordString .= $selectedChar;
    }
    }

    //5 - lowercase (97[a] to 122[z]) + uppercase (65[A] to 90[Z]) + numbers (48[0] to 57[9]) - 62
    if($characterSet==5)
    {
    $passwordString = "";
    for($i=0; $i<$passwordLength; $i++)
    {
    $selectedChar = rand(1, 62);
    if($selectedChar>=1&&$selectedChar<=10)
    {
    $selectedChar = $selectedChar + 47;
    $selectedChar = chr($selectedChar);
    }
    elseif($selectedChar>=11&&$selectedChar<=36)
    {
    $selectedChar = $selectedChar + 54;
    $selectedChar = chr($selectedChar);
    }
    else
    {
    $selectedChar = $selectedChar + 60;
    $selectedChar = chr($selectedChar);
    }
    $passwordString .= $selectedChar;
    }
    }

    //6 - full keyboard set (32 to 126) less space (32[space], 34["], 39['], 96[`]) - 91
    if($characterSet==6)
    {
    $passwordString = "";
    for($i=0; $i<$passwordLength; $i++)
    {
    $selectedChar = rand(1, 91);
    if($selectedChar==1)
    {
    $selectedChar = $selectedChar + 32;
    $selectedChar = chr($selectedChar);
    }
    elseif($selectedChar>=2&&$selectedChar<=5)
    {
    $selectedChar = $selectedChar + 33;
    $selectedChar = chr($selectedChar);
    }
    elseif($selectedChar>=6&&$selectedChar<=61)
    {
    $selectedChar = $selectedChar + 34;
    $selectedChar = chr($selectedChar);
    }
    else
    {
    $selectedChar = $selectedChar + 35;
    $selectedChar = chr($selectedChar);
    }
    $passwordString .= $selectedChar;
    }
    }

    return $passwordString;
    }


    //Example Usage
    $randomPass = generatePassword (12, 1);
    echo "Set 1: ".$randomPass."<br />";
    $randomPass = generatePassword (12, 2);
    echo "Set 2: ".$randomPass."<br />";
    $randomPass = generatePassword (12, 3);
    echo "Set 3: ".$randomPass."<br />";
    $randomPass = generatePassword (12, 4);
    echo "Set 4: ".$randomPass."<br />";
    $randomPass = generatePassword (12, 5);
    echo "Set 5: ".$randomPass."<br />";
    $randomPass = generatePassword (12, 6);
    echo "Set 6: ".$randomPass."<br />";

    ?>
    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 Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    Check out the new Jazz space on developerWorks

    <a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts.
    FREE! Go There Now!


    NEW! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT