Hi all,
I was just reading my c# book on some functions and spotted the random function, and I came up with makeing a small password generator. it very basic but seems to do the tick the code is also small anyway thought I share it with you. Hope you find it usfull comments are welcome.
Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { //Random chars to pick a password from const string iChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Random Rnd = new Random(); StringBuilder sb = new StringBuilder(); for (int x = 0; x < 10; x++) { //Pull out a random number int RndNum = Rnd.Next(iChars.Length - 1); //Build the random string. sb.Append(iChars[RndNum]); } //Display random string MessageBox.Show("Here is your random password: " + sb.ToString()); } } }




Reply With Quote