パスワードの生成
パスワードっぽい文字列を生成するクラスを書いた。static にしてるので、
string passwd = GenPass.Exec();
みたいに使います。
perl モジュールのgenpassをそっくりそのまま移植したような感じ(つーかまるパクリ)。見間違いやすそうな、oとOと0とlと1とIあたりを抜いてます。
using System; using System.Collections.Generic; using System.Text; namespace SomeThing { public class GenPass { private const int length = 8; //パスワードに使えそうな文字 private static char[] chars = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '2', '3', '4', '5', '6', '7', '8', '9', }; private static Random r = new Random(); public static string Exec() { string passwd = ""; for ( int i = 0; i < length; i++ ) passwd += chars[r.Next(chars.Length)]; return passwd; } } }