1. Technology

Your suggestion is on its way!

An email with a link to:

http://javascript.about.com/library/blpasswd1.htm

was emailed to:

Thanks for sharing About.com with others!

Password Generator Tutorial

Page One

The password generator script makes quite a lot of use of the various array methods. This makes it an interesting script to look at to see how these array methods can be combined together to produce a useful program. We're not just going to look at the array code though, we'll look at all of the code in this script and what the individual statements are for so that you can see how I built this program and perhaps get some ideas of how you can build your own Javascript programs. In any case working through this tutorial will give you an insight into how I develop Javascript programs.

We'll start at the beginning of the code and work our way through the code line by line and consider what each individual statement does and what purpose it serves in the program.

var numChars = '0123456789';
var lowerChars = 'abcdefghijklmnopqrstuvwxyz';
var upperChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var otherChars = '~!@#$%^&*()-_=+[{]}\\|<>/?';

We start the script by defining all of the characters that can appear in the generated passwords and breaking them up into the four different types of characters. I initially was thinking of using string methods to generate these entries but in the end decided that just coding them was simpler to write and would produce faster running code.

function randOrd(a, b){
return (Math.round(Math.random())-0.5);
}

This function will be used to sort our array into random order.

©2014 About.com. All rights reserved.