Miscellaneous Code
  Home arrow Miscellaneous Code arrow Random Password Generator
IBM Rational Software Development Conference
FaxWave - Free Trial.
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  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
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 / 8
    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
     
     
    FaxWave - Free Trial.
     
    ADVERTISEMENT

    Virtual Tradeshows by Ziff Davis Enterprise - A Unique Opportunity to Connect with IT Experts, Access Information, and Gain Insight on today's Technology

    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! 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! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    FREE! Go There Now!


    NEW! Best Practices: The Integrated Project and Portfolio Management Platform.

    Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan.
    FREE! Go There Now!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Write REST services

    This tutorial discusses the concepts of REST and the Atom Publishing Protocol (APP) and shows how they apply to services. It also shows how to use Java technology to implement REST/APP-based services.
    FREE! Go There Now!


    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! Rational Testing eKits

    Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    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! Develop with Java and PHP technology on AIX Version 5.3, Part 6: Building the Java business application

    Set up a PHP Web interface for the Java(TM) business application using a database created in earlier in this series. The PHP Web interface collects information from users and sends the session data to the Java business application for processing and for a response.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - 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
    - [PHP5] NOTIMEOUT PACKAGE
    - Class to return variables to a Flash movie.
    - BCGCD Greatest Common Denominator (Large Num...
    - HMAC
    - Binary to Decimal
    - Decimal to Binary using logs
    - web.framework v1.0.0
    - Shopping Cart Class


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway