Skip to main content
fixed list-item misindentation
Source Link
Vogel612
  • 25.3k
  • 7
  • 58
  • 141
  1. 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.
  2. 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?
  3. 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);
    }
    
    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);
}
  1. 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.

  2. Could I somehow remove those possibilities as strings to make it more secure?

  3. 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);
    }
    
  1. 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.
  2. Could I somehow remove those possibilities as strings to make it more secure?
  3. 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);
}
Source Link
the_endian
  • 1.3k
  • 13
  • 25

Random Password Generator in C#

Security is a huge complicated subject. What I'm looking for here is three things:

  1. 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.

  2. Could I somehow remove those possibilities as strings to make it more secure?

  3. 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);
    }