Generating Random, Human-Readable Passwords in C#.NET

I recently had the need to generate pronounceable, random passwords in .NET.  First, I looked at the built-in ASP.NET method for generating random passwords, but that makes them completely unreadable with crazy symbols and numbers.  After looking a bit more, I could not find an easy solution – so I wrote this class.  Feel free to use it for whatever you like.  But if you have improvements, please let me know in the comments so I can update it!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RandomPasswordGenerator
{
public static class RandomPassword
{
private static Random rand = new Random();

private static readonly char[] VOWELS = new char[] { ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ };
private static readonly char[] CONSONANTS = new char[] { ‘b’, ‘c’, ‘d’, ‘f’, ‘g’, ‘h’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’ };
private static readonly char[] SYMBOLS = new char[] { ‘*’, ‘?’, ‘/’, ‘\\’, ‘%’, ‘$’, ‘#’, ‘@’, ‘!’, ‘~’ };
private static readonly char[] NUMBERS = new char[] { ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’ };

/// <summary>
/// Generates a random, human-readable password.
///
/// </summary>
/// <param name=”numSyllables”>Number of syllables the password will contain</param>
/// <param name=”numNumeric”>Number of numbers the password will contain</param>
/// <param name=”numSymbols”>Number of symbols the password will contain</param>
/// <returns></returns>
public static string Generate(int numSyllables, int numNumeric, int numSymbols)
{
StringBuilder pw = new StringBuilder();
for (int i = 0; i < numSyllables; i++)
{
pw.Append(MakeSyllable());

if (numNumeric > 0 && ((rand.Next() % 2) == 0))
{
pw.Append(MakeNumeric());
numNumeric–;
}

if (numSymbols > 0 && ((rand.Next() % 2) == 0))
{
pw.Append(MakeSymbol());
numSymbols–;
}
}

while (numNumeric > 0)
{
pw.Append(MakeNumeric());
numNumeric–;
}

while (numSymbols > 0)
{
pw.Append(MakeSymbol());
numSymbols–;
}

return pw.ToString();
}

private static char MakeSymbol()
{
return SYMBOLS[rand.Next(SYMBOLS.Length)];

}private static char MakeNumeric()
{
return NUMBERS[rand.Next(NUMBERS.Length)];
}

private static string MakeSyllable()
{
int len = rand.Next(3, 5); // will return either 3 or 4

StringBuilder syl = new StringBuilder();
for (int i = 0; i < len; i++)
{
char c;
if (i == 1) // the second should be a vowel, all else a consonant
c = VOWELS[rand.Next(VOWELS.Length)];
else
c = CONSONANTS[rand.Next(CONSONANTS.Length)];

// only first character can be uppercase
if (i == 0 && (rand.Next() % 2) == 0)
c = Char.ToUpper(c);

// append
syl.Append(c);
}

return syl.ToString();
}
}
}

Greybox and Firefox Back Button Issue

I started using Greybox for one of my web projects recently.  I like it because it’s a little different that plain old lightbox.

BUT, there was a problem.  In Firefox, after viewing a image and closing it, the back button would no longer work.  The workaround was found by Jani at http://amix.dk/blog/viewEntry/19039

Hello,
Regarding the issue with the back button in Firefox, i think i found a solution.
First i came with this suggestion:
http://efrtw.spaces.live.com/Blog/cns!68A490680B58FBDC!139.entry

I did tweak the script a bit more, and now it seems to work fine in firefox.
Here is the new script for version 5.53:

http://myfreefilehosting.com/f/aeaad9cb1c_0.01MB

The new gb_scripts.js file worked great!

Cool Web 2.0 Sites I’ve Found

Here are some neat “Web 2.0” sites that I’ve found recently.  Mostly, I found them through go2web20.net.

  • Zenbe.com – This is basically a web-base e-mail/calendar/contact manager.  I like it because it consolidates my e-mail and calendar into one app.  I’ve never liked webmail – or desktop mail clients – but this one pretty takes the good from both and puts in into one app.  You can download mail from any POP3 mail server
  • Powerset.com – This search engine uses “natural language processing” to figure out the meaning behind sentences, rather than just using keywords.  I’ve been following this site for quite a while because it really sparked my interest. As of this writing, it only search Wikipedia but they plan to expand that, hopefully, to the entire Internet.
  • ribbit.com – Visual voicemail, like on the iPhone but for any phone.  Supposed to convert the voice to text.  Not released yet, but I can’t wait to try it because I would love being able to visually see the list of voicemails, who they’re from, and read them, rather than listen through them all.
  • filemail.com – easy way to send large files over the Internet.  It’s not really very secure, but it is very easy to use.