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!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! Download IBM WebSphere Portal V6.1 beta code

    Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization.
    FREE! Go There Now!


    NEW! Harnessing the power of SQL and Java for high performance data access

    Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository.
    FREE! Go There Now!


    NEW! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    FREE! Go There Now!


    NEW! Software Change and Configuration Management Solution Guidelines

    This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Webcast: Striking the right balance between manual and automated testing

    Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable.
    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek