This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Random _random = new Random(); | |
public static string Base64Hash() | |
{ | |
byte[] buffer = GetRandom(4); | |
return Convert.ToBase64String(buffer); | |
} | |
// <summary> | |
// This is used by all Unique identifier examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string NumberHash() | |
{ | |
byte[] buffer = GetRandom(2); | |
return string.Format("{0:00}-{1:00}",buffer[0],buffer[1]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string AlphaNumeric() | |
{ | |
string s = "abcdefghijklmnopqrstuvwxyz0123456789"; | |
StringBuilder builder = new StringBuilder(); | |
Random random = new Random(); | |
for (int i = 0; i < 4; i++) | |
{ | |
int index = _random.Next(1, 36); | |
builder.Append(s[index]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string HostnameHash(Uri uri) | |
{ | |
// e.g. Uri uri = new Uri("http://www.yetanotherchris.info/csharp/example"); | |
// gives eaafc653 | |
int hashcode = uri.GetHashCode(); | |
Console.Write(string.Format("{0:X}", hashcode).ToLower()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string TimeToHexString() | |
{ | |
long ms = DateTime.Now.Second; | |
long ms2 = DateTime.Now.Millisecond; | |
return string.Format("{0:X}{1:X}", ms, ms2).ToLower(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string TicksToString() | |
{ | |
long ticks = DateTime.Now.Ticks; | |
return string.Format("{0:X}", ticks).ToLower(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string RandomMD5() | |
{ | |
byte[] buffer = GetRandom(16); | |
MD5 md5 = System.Security.Cryptography.MD5.Create(); | |
byte[] output = md5.ComputeHash(buffer); | |
StringBuilder builder = new StringBuilder(); | |
for (int i = 0; i < output.Length; i++) | |
builder.AppendFormat("{0:x2}", output[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string Base62Random() | |
{ | |
int random = _random.Next(); | |
return Base62ToString(random); | |
} | |
private static string Base62ToString(long value) | |
{ | |
// Divides the number by 64, so how many 64s are in | |
// 'value'. This number is stored in Y. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DesignPatterns | |
{ | |
/// <summary> | |
/// Default State that every state inherits from. | |
/// </summary> | |
public abstract class State | |
{ | |
/// <summary> | |
/// Holds the current state we're in. | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Text; | |
// Example usage | |
void Main() | |
{ | |
PronounceablePasswordGenerator generator = new PronounceablePasswordGenerator(); | |
int numPasswords = 5; | |
int passwordLength = 10; |