The password generating algorithm isn't reversible, meaning that when someone looks at the source code of this application, that won't help them to break passwords made by it other than the fact that they can see the possibilities as strings there.
The password generating algorithm isn't reversible, meaning that when someone looks at the source code of this application, that won't help them to break passwords made by it other than the fact that they can see the possibilities as strings there.Could I somehow remove those possibilities as strings to make it more secure?
Could I somehow remove those possibilities as strings to make it more secure?Am I overlooking any potential memory issues e.g. should I be zeroing/wiping memory in areas where the password is stored after?
Am I overlooking any potential memory issues e.g. should I be zeroing/wiping memory in areas where the password is stored after?enum Password_Options { ALPHANUM, ALL } private string CreatePassword(int length, Password_Options options) { const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; const string valid_all = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-=+{}:;\\<>?|,./`~[]'"; if (options == Password_Options.ALPHANUM){ StringBuilder res = new StringBuilder(); byte[] random = new byte[1]; RNGCryptoServiceProvider rProvider = new RNGCryptoServiceProvider(); while (0 < length--){ rProvider.GetBytes(random); res.Append(valid[random[0] % (valid.Length - 1)]); } return res.ToString(); } else{ StringBuilder res = new StringBuilder(); byte[] random = new byte[1]; RNGCryptoServiceProvider rProvider = new RNGCryptoServiceProvider(); while (0 < length--) { rProvider.GetBytes(random); res.Append(valid_all[random[0] % (valid_all.Length - 1)]); } return res.ToString(); } } private void button1_Click(object sender, EventArgs e) { Password_Options po; if (radioButton1.Checked){ po = Password_Options.ALL; } else{ po = Password_Options.ALPHANUM; } textBox1.Text = CreatePassword((int)numericUpDown1.Value,po); }
enum Password_Options
{
ALPHANUM,
ALL
}
private string CreatePassword(int length, Password_Options options)
{
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
const string valid_all = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-=+{}:;\\<>?|,./`~[]'";
if (options == Password_Options.ALPHANUM){
StringBuilder res = new StringBuilder();
byte[] random = new byte[1];
RNGCryptoServiceProvider rProvider = new RNGCryptoServiceProvider();
while (0 < length--){
rProvider.GetBytes(random);
res.Append(valid[random[0] % (valid.Length - 1)]);
}
return res.ToString();
}
else{
StringBuilder res = new StringBuilder();
byte[] random = new byte[1];
RNGCryptoServiceProvider rProvider = new RNGCryptoServiceProvider();
while (0 < length--)
{
rProvider.GetBytes(random);
res.Append(valid_all[random[0] % (valid_all.Length - 1)]);
}
return res.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
Password_Options po;
if (radioButton1.Checked){
po = Password_Options.ALL;
}
else{
po = Password_Options.ALPHANUM;
}
textBox1.Text = CreatePassword((int)numericUpDown1.Value,po);
}