I have put the key maker code below:
Thank you if you can help, I'm new to VB and with limited knowledge of programing, learning.
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;
using System.Threading;
using System.IO;
namespace WindowsFormsApplication1
{
//Password types
enum iGenType {
Alpha,
Numeric,
AlphaNumeric
};
public partial class Form1 : Form
{
private iGenType GenType;
//Random chars to pick a password from
private const string iAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private const string iNumeric = "0123456789";
private const string iAlphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public Form1()
{
InitializeComponent();
}
private void ShowError(string message)
{
MessageBox.Show("Invaild value " + message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private static string MakePassword(int Length, iGenType PasswordType, Random Rnd)
{
StringBuilder sb = new StringBuilder();
for (int x = 0; x < Length; x++)
{
//Build alpha only password
if (PasswordType == iGenType.Alpha)
{
//Pull out a random number
int RndNum = Rnd.Next(iAlpha.Length - 1);
//Build the random string.
sb.Append(iAlpha[RndNum]);
}
//Build Numeric only password
if (PasswordType == iGenType.Numeric)
{
//Pull out a random number
int RndNum = Rnd.Next(iNumeric.Length - 1);
//Build the random string.
sb.Append(iNumeric[RndNum]);
}
//Build AlphaNumeric password
if (PasswordType == iGenType.AlphaNumeric)
{
//Pull out a random number
int RndNum = Rnd.Next(iAlphaNumeric.Length - 1);
//Build the random string.
sb.Append(iAlphaNumeric[RndNum]);
}
}
//Display random string
return sb.ToString();
}
private void r1_CheckedChanged(object sender, EventArgs e)
{
GenType = iGenType.Alpha;
}
private void r3_CheckedChanged(object sender, EventArgs e)
{
GenType = iGenType.AlphaNumeric;
}
private void r2_CheckedChanged(object sender, EventArgs e)
{
GenType = iGenType.Numeric;
}
private void cmdMake_Click(object sender, EventArgs e)
{
int iLen = 0;
int iPasswords = 0;
try
{
iLen = Convert.ToInt32(txtLength.Text);
if (iLen == 0) return;
}
catch
{
txtLength.Text = "8";
ShowError("password length");
return;
}
try
{
iPasswords = Convert.ToInt32(txtKeys.Text);
}
catch
{
txtKeys.Text = "10";
ShowError("number of passwords");
return;
}
Random Rnd = new Random();
//Make passwords
LstPws.Items.Clear();
//Build password list
for (int Counter = 0; Counter < iPasswords; Counter++)
{
LstPws.Items.Add(MakePassword(iLen, GenType, Rnd));
}
}
private void cmdSave_Click(object sender, EventArgs e)
{
if (LstPws.Items.Count == 0)
{
MessageBox.Show("Nothing to save.",
"Nothing In List", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save Passwords";
sfd.Filter = "Text Files(*.txt)|*.txt";
if (sfd.ShowDialog() == DialogResult.OK)
{
//Create the file
using (StreamWriter sw = new StreamWriter(sfd.FileName))
{
foreach (string Item in LstPws.Items)
{
//Write each password to the file
sw.WriteLine(Item);
}
sw.Close();
}
}
}
}
private void cmdAbout_Click(object sender, EventArgs e)
{
MessageBox.Show(this.Text + " Created 2010",
"About", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void cmdExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void LstPws_SelectedIndexChanged(object sender, EventArgs e)
{
//Show password in text box
txtPws.Text = LstPws.SelectedItem.ToString();
}
private void label2_Click(object sender, EventArgs e)
{
}
}
private void cmdCpy_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtPws.Text))
{
//Copy password to clipboard.
Clipboard.SetText(txtPws.Text);
}
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void txtLength_TextChanged(object sender, EventArgs e)
{
}
private void txtKeys_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
private void txtPws_TextChanged(object sender, EventArgs e)
{
}
}

New Topic/Question
Reply



MultiQuote




|