CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    5

    Help with function, password checker

    Aim - trying to create a password strength checker that updates the progress bar as user types in password. keep getting errors. not to familiar with byref and function

    Public Function PasswordQuality(LengthScore As Integer, _
    UCaseScore As Integer, LCaseScore As Integer, _
    NumberScore As Integer, SpecCharScore As Integer, _
    TotalScore As Integer) As Integer



    Const Space As String = " "
    Dim Uppercase As Boolean
    Dim UCaseScore As Integer
    Dim LengthScore As Integer
    Dim Lowercase As Boolean
    Dim LCaseScore As Integer
    Dim Numbers As Boolean
    Dim NumberScore As Integer
    Dim SpecialChar As Boolean
    Dim SpecCharScore As Integer
    Dim TotalScore As Integer
    Dim PasswordLength As Long
    Const Space As String = " "

    PasswordLength = Len(Text1.Text)

    If InStr(Text1.Text, Space) > 0 Then
    MsgBox "Please make sure that the password you have entered does not contain any spaces", vbInformation + vbOKOnly, "Incorrect password"
    Exit Function
    End If

    If Len(Text1.Text) < 6 Then
    MsgBox "Please make sure that the password is greater than 6 characters", vbInformation + vbOKOnly, "Incorrect password"
    Exit Function
    End If

    If Len(Text1.Text) > 6 Then
    LengthSscore = 20
    If Asc(Text1.Text) > 64 And Asc(Text1.Text) < 91 Then Uppercase = True
    UCaseScore = 20
    If Ascii(Text1.Text) > 96 And Asc(Text1.Text) < 123 Then Lowercase = True
    LCaseScore = 10
    If Ascii(Text1.Text) > 47 And Asc(Text1.Text) < 58 Then Numbers = True
    NumberScore = 20
    If Ascii(Text1.Text) > 32 And Asc(Text1.Text) < 48 Then SpecialChar = True
    SpecCharScore = 20
    End If

    TotalScore = LengthScore + UCScore + LCaseScore + NumberScore + SpecCharScore
    PasswordQuality = TotalScore
    End Function



    Private Sub Text1_Change()
    ProgressBar1.Value = PasswordQuality
    End Sub

    any help would be appreciated

  2. #2
    Join Date
    Feb 2010
    Posts
    5

    Re: Help with function, password checker

    have corrected the ascii( errors already and lengthSscore = 20 still errors though.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help with function, password checker

    Correct the code by using TAGS, and also post what error occurs on what line

    Code:
    '  Like THIS
    Also, look at this code (by itself)
    Code:
    Option Explicit
    
    Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    
    Private Sub Form_Activate()
      ProgressBar1.Min = 0
      ProgressBar1.Max = 100
      ProgressBar1.Value = 0
      ProgressBar1.Enabled = True
      Dim x As Integer
      Dim q As Long
      For x = 0 To 100
        DoEvents
        ProgressBar1.Value = x
        Sleep 50
      Next x
      MsgBox "Done"
      Unload Me
    End Sub
    Run it and see the bar update
    Last edited by dglienna; December 19th, 2010 at 05:41 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Help with function, password checker

    You can't use ASC nor ASCII in the way that you are attempting in the OP. If you want to check the string to see if a given character is Upper or Lower case you must use another method.

    ASC() returns the numeric character value of a single character not of a string of characters.

    You need to loop through the string and check each character one by one to get the result you seem to be looking for.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured