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 6843455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:14:49+00:00 2026-05-27T00:14:49+00:00

I have inherited some legacy vb6 code. It’s a tool which generates a local

  • 0

I have inherited some legacy vb6 code. It’s a tool which generates a local admin password for a windows pc. The password is supposed to contain only a limited set of characters. The tool works fine.. as long as it’s not run on chinese or russian PCs. There, it generates weird passwords that nobody can type in. Of course it has something to do with the current operating system culture. The Chr(CharCode) function returns some weird characters on those systems. Anyone has a clue on how to make this culture invariant? I only want the tool to generate passwords with standard ASCII characters.

Function generatePassword(PASSWORD_LENGTH)
Dim NUMLOWER, NUMUPPER, LOWERBOUND, UPPERBOUND, LOWERBOUND1, UPPERBOUND1, SYMLOWER, SYMUPPER
Dim newPassword, count, pwd
Dim pCheckComplex, pCheckComplexUp, pCheckComplexLow, pCheckComplexNum, pCheckComplexSym, pCheckAnswer

  NUMLOWER = 48     ' 48 = 0
  NUMUPPER = 57     ' 57 = 9
  LOWERBOUND = 65   ' 65 = A
  UPPERBOUND = 90   ' 90 = Z
  LOWERBOUND1 = 97  ' 97 = a
  UPPERBOUND1 = 122 ' 122 = z
  SYMLOWER = 33     ' 33 = !
  SYMUPPER = 46     ' 46 = .
  pCheckComplexUp = 0  ' used later to check number of character types in password
  pCheckComplexLow = 0 ' used later to check number of character types in password
  pCheckComplexNum = 0 ' used later to check number of character types in password
  pCheckComplexSym = 0 ' used later to check number of character types in password

  ' initialize the random number generator
  Randomize

  newPassword = ""
  count = 0
  Do Until count = PASSWORD_LENGTH
    ' generate a num between 2 and 10

    ' if num <= 2 create a symbol
    If Int((10 - 2 + 1) * Rnd + 2) <= 2 Then
      'pwd = Int( ( SYMUPPER - SYMLOWER + 1 ) * Rnd + SYMLOWER )

      pwd = Int((UPPERBOUND1 - LOWERBOUND1 + 1) * Rnd + LOWERBOUND1)

      ' if num is between 3 and 5 create a lowercase
    ElseIf Int((10 - 2 + 1) * Rnd + 2) > 2 And Int((10 - 2 + 1) * Rnd + 2) <= 5 Then
      pwd = Int((UPPERBOUND1 - LOWERBOUND1 + 1) * Rnd + LOWERBOUND1)

      ' if num is 6 or 7 generate an uppercase
    ElseIf Int((10 - 2 + 1) * Rnd + 2) > 5 And Int((10 - 2 + 1) * Rnd + 2) <= 7 Then
      pwd = Int((UPPERBOUND - LOWERBOUND + 1) * Rnd + LOWERBOUND)

    Else
      pwd = Int((NUMUPPER - NUMLOWER + 1) * Rnd + NUMLOWER)
    End If

    If Chr(pwd) <> "l" And Chr(pwd) <> "I" Then
      newPassword = newPassword + Chr(pwd)

      count = count + 1
    End If

    'Check to make sure that a proper mix of characters has been created.  If not discard the password.
    If count = (PASSWORD_LENGTH) Then
      For pCheckComplex = 1 To PASSWORD_LENGTH
        'Check for uppercase
        If Asc(Mid(newPassword, pCheckComplex, 1)) > 64 And Asc(Mid(newPassword, pCheckComplex, 1)) < 90 Then
          pCheckComplexUp = 1
        'Check for lowercase
        ElseIf Asc(Mid(newPassword, pCheckComplex, 1)) > 96 And Asc(Mid(newPassword, pCheckComplex, 1)) < 123 Then
          pCheckComplexLow = 1
        'Check for numbers
        ElseIf Asc(Mid(newPassword, pCheckComplex, 1)) > 47 And Asc(Mid(newPassword, pCheckComplex, 1)) < 58 Then
          pCheckComplexNum = 1
        'Check for symbols
        ElseIf Asc(Mid(newPassword, pCheckComplex, 1)) > 32 And Asc(Mid(newPassword, pCheckComplex, 1)) < 47 Then
          pCheckComplexSym = 1
        End If
      Next

      'Add up the number of character sets.  We require 3 or 4 for a complex password.
      pCheckAnswer = pCheckComplexUp + pCheckComplexLow + pCheckComplexNum + pCheckComplexSym

      If pCheckAnswer < 3 Then
        newPassword = ""
        count = 0
      End If
    End If
  Loop
  'The password is good so return it
  generatePassword = newPassword
End Function
  • 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-27T00:14:49+00:00Added an answer on May 27, 2026 at 12:14 am

    Deanna’s comment is correct. Just change Chr to ChrW and change Asc to AscW.

    • ChrW accepts Unicode code points
    • Chr accepts “ANSI” code points, and the meaning of a particular code point will be different depending on the system code page. For example on Chinese and Russian code pages.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited some legacy code which generates a ton of inline styles. The
I have some inherited code which stores SMTP server, username, password in the system.net/mailSettings/smtp
I have inherited some legacy PHP code what was written back when it was
I have inherited some legacy HTML in which it has the following elements in
I have inherited some code which involves a scheduled task that writes data (obtained
I have inherited some ASP.NET web code which I have made changes to. It
I have inherited some HTML code and have been asked to align the two
I have inherited some code: Process p = new ProcessBuilder(/bin/chmod, 777, path).start(); p.waitFor(); Basically,
I have inherited some code (from zip file) from a developer and git initialzed,
I have inherited a visual studio 2003 project which uses some custom build steps.

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.