Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:27:08+00:00 2026-05-24T08:27:08+00:00

I have a quick question. I have a keygen to generate random passwords for

  • 0

I have a quick question. I have a keygen to generate random passwords for my app. It generates capital letters and numbers but I want it to be like in some programs that formats their code like this xxxx-xxxx-xxxx. so far my code is this

Random random = new Random(0);

private void button1_Click(object sender, EventArgs e)
{
    textBox1.Text = getrandomcode();
}

public string getrandomcode()
{
    char[] tokens = {'0', '1', '2', '3', '4', '5', '7', '8', '9', 'A', 'B', 'C', 
        'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
        'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

    char[] codeArray = new char[24];

    for (int i = 0; i < 24; i++)
    {
        int index = random.Next(tokens.Length - 1);
        codeArray[i] = tokens[index];
    }

    return new String(codeArray);
}

Its something simple not to complex so I hope there is a way to implement the “-” to this code.

thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:27:10+00:00Added an answer on May 24, 2026 at 8:27 am

    Try this:

    for (int i = 0; i < 24; i++)
    {
        if (i % 5 == 4) {
            codeArray[i] = '-';
        } else {
            int index = random.Next(tokens.Length - 1);
            codeArray[i] = tokens[index];
        }
    }
    

    If you want your password to have 24 non-dash characters, change the 24 to 29.

    But I also have to tell you that using a random function seeded with 0 is not a very secure way to generate passwords. If the application is stopped and restarted, it will generate the same set of passwords the second time that it did the first time. It is better to not pass an initialization argument in which case it will use the time to seed the random number generator.

    If these passwords are going to be used for something important or something which the whole world can access (or both), then even this isn’t really random enough to be secure. You should look at cryptographic random number generators like System.Security.Cryptography.RNGCryptoServiceProvider

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a quick question on iAd I would like to create a free app
Quick question... I have a query that checks for duplicates that looks like this:
Quick question. I have an app that use a native DLL through PInvoke, this
I have quick question, and it may sound dumb. But for the love of
I have a quick question. As the title says, I'd like to find a
I have a quick question. Is it possible to do something like this? The
I have a quick question about while loop. I want to read ASCII char
I have a quick question. I have a function like this: function clean_num($num){ return
I have quick question for you SQL gurus. I have existing tables without primary
I have a quick question about fetching results from a weakly typed cursor and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.