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

  • Home
  • SEARCH
  • 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 8435537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:56:32+00:00 2026-06-10T06:56:32+00:00

Trying to make a random password generator in VB.NET So far have got this,

  • 0

Trying to make a random password generator in VB.NET

So far have got this, but it only returns the first section of what im trying to do

I have 3 inputs for Type of password as checkboxes, in this order:

Numeric
Alphabetic
Symbols

If i have numeric checked it returns a numeric password, but if i have numeric and alphabetic checked it only returns a numeric password, although if i uncheck numeric and only have alphabetic checked it then returns and alphabetic password

An alphabetic password also has three options:

Uppercase
Lowercase
Mixed Case

Which when used with alphabetic actually returns the correct password

Here is the code i have so far:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    C_Numeric.Checked = True
    R_Upper.Checked = True
End Sub

Private Sub B_Generate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_Generate.Click
    Dim c_a As Boolean = False
    Dim c_b As Boolean = False
    Dim c_c As Boolean = False
    Dim a As Integer
    If C_Numeric.Checked = True Then
        c_a = True
    ElseIf C_Alphabetic.Checked = True Then
        c_b = True
    ElseIf C_Symbols.Checked = True Then
        c_c = True
    End If
    If R_Lower.Checked = True Then
        a = 1
    ElseIf R_Upper.Checked = True Then
        a = 2
    ElseIf R_Mixed.Checked = True Then
        a = 3
    End If
    If C_Numeric.Checked = True Or C_Alphabetic.Checked = True Or C_Symbols.Checked = True Then
        TextBox1.Text = GenPass(NumericUpDown1.Value, c_a, c_b, c_c, a)
    End If
End Sub

Function GenPass(ByVal Length As Integer, ByVal Num As Boolean, ByVal Alp As Boolean, ByVal Ascii As Boolean, ByVal Complexity As Integer)
    Dim rand As New Random
    Dim Pass As String = ""
    Do Until Pass.Length = Length
        Dim a As Integer
        a = rand.Next(1, 3 + 1)
        If a = 1 And Num = True Then
            Pass += ChrW(rand.Next(Asc("0"), Asc("9") + 1))
        End If
        If a = 2 And Alp = True Then
            If Complexity = 1 Then
                Pass += ChrW(rand.Next(Asc("a"), Asc("z") + 1))
            ElseIf Complexity = 2 Then
                Pass += ChrW(rand.Next(Asc("A"), Asc("Z") + 1))
            ElseIf Complexity = 3 Then
                Dim b As Integer
                b = rand.Next(1, 2 + 1)
                If b = 1 Then
                    Pass += ChrW(rand.Next(Asc("A"), Asc("Z") + 1))
                ElseIf b = 2 Then
                    Pass += ChrW(rand.Next(Asc("a"), Asc("z") + 1))
                End If
            End If
        End If
        If a = 3 And Ascii = True Then
            Dim b As Integer
            b = rand.Next(1, 4 + 1)
            If b = 1 Then
                Pass += ChrW(rand.Next(Asc("!"), Asc("/") + 1))
            ElseIf b = 2 Then
                Pass += ChrW(rand.Next(Asc(":"), Asc("@") + 1))
            ElseIf b = 3 Then
                Pass += ChrW(rand.Next(Asc("["), Asc("`") + 1))
            ElseIf b = 4 Then
                Pass += ChrW(rand.Next(Asc("{"), Asc("~") + 1))
            End If
        End If
    Loop
    Return (Pass)
End Function

For Example (Assume Length is 16 for all answers):

Having Numeric and Alphabetic selected with Mixed Case Should return:

eVOv3fyTmW7mvH24 CZOXVzeo1EzLu7Al V313p9VLW0Bz7Zfi 

But instead returns:

8343299372194893 7303963979299152 3918539496952829

I Have not got a clue why is it not actually returning the desired results

Any help would be appreciated

Adam

  • 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-06-10T06:56:34+00:00Added an answer on June 10, 2026 at 6:56 am

    It’s because of

    If C_Numeric.Checked = True Then
        c_a = True
    ElseIf C_Alphabetic.Checked = True Then
        c_b = True
    ElseIf C_Symbols.Checked = True Then
        c_c = True
    End If
    

    So if C_Numeric and C_Alphabetic are checked, c_a gets True, but the line setting c_b to True won’t be hit due to the ElseIf.

    So, remove the Else part.


    Also, you could simplify this code by writting:

    c_a = C_Numeric.Checked 
    c_b = C_Alphabetic.Checked 
    c_c = C_Symbols.Checked 
    

    instead of the If clauses, or better, getting rid of those unnecessary variables by just calling:

    GenPass(NumericUpDown1.Value, C_Numeric.Checked, C_Alphabetic.Checked, C_Symbols.Checked, a)
    

    There are a lot more improvements possbile. For example, instead of passing the Complexity parameter as Integer, create an Enum:

    Enum Complexity
        LowerOnly
        UpperOnly
        Mixed
    End Enum
    
    Function GenPass(Length As Integer, Num As Boolean, Alp As Boolean, Ascii As Boolean, Complexity As Complexity)
    

    If you’re using VB 10.0 (introduced with .Net 4.0), you can get rid of the clunky ByVal keyword. Also, the .Net Naming Guidelines in.


    Some more notes:

    If you’re checking a boolean value in an If clause, there’s no need to explicitly write = True:

    If a = 3 And Ascii = True Then
    

    could be written as

    If a = 3 AndAlso Ascii Then
    

    Note that AndAlso is generally better suited as And due to it’s short-circut behaviour.

    Also, better name your parameter useAcii instead of Acii. It will make it more clearer.

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

Sidebar

Related Questions

So I'm trying to make an incrementer similar to this: http://www.usagain.com/ but I'm apparently
I am trying to make a random chat with ASP.NET and ajax/jquery. When user
I m trying to make a random number generator in android. My code has
Trying to make this script go random. I tried variations of this string $banner_no
I have a password generator that uses the ascii table. I am trying to
I'm trying to make the Bubble sort, and this is my code: import java.util.Random;
I'm trying to make each span rotate between a random color on 3sec intervals.
Ok I am trying to make something to ask you random multiplication questions. Now
I am trying to make an array of strings and then pluck a random
I am trying to make a Java implementation of the Park-Miller-Carta PRNG random number

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.