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!


    Build Forge Express demo: Enabling software delivery excellence for small and midsized businesses

    This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! Evaluate Rational Host Access Transformation Services (HATS) Toolkit V7.1

    Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    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! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! The role of integrated requirements management in software delivery

    This paper is about the critical role that a discipline called integrated require­ments management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrat­ing, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    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-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek