none
Password Strength Checker Program - help? RRS feed

  • General discussion

  • Hi

    I'm looking to show my class how to make a password strength indicator. This is what I want to do, how if at all can it be done in Small Basic?

    Program should check if the password has any lowercase letters, any uppercase letters and any numbers. If password only has one of the 3, then it should tell them it is a weak password. If it contains 2 of the 3, it should tell them it is medium strength, if all 3 it should say it is strong.

    any help much appreciated.

    cheers

    Wednesday, January 29, 2014 9:27 PM

All replies

  • Yes this is completely feasible in SmallBasic.  Functionality to do the following exists:

    1. Read a password in
    2. step through each character
    3. get the ascii code integer for the character
    4. check if the letter is a lower, upper case letter or a number (from the ascii code)
    5. store the number of each character type
    6. output stats on the password strength according the the count of each type
    7. it can even check if the input is a word using the Dictionary object - very bad password

    Wednesday, January 29, 2014 11:46 PM
    Moderator
  • My 1st intention was just give ya some tips about using Text.GetCharacterCode() in order to define character range groups.  :P

    However, T'was easy enough and I've ended up finishing the whole task!  :D

    Check it out below. Any doubts, don't fret to ask:

    ' Password Strength Checker (v1.01)
    ' by GoToLoop (2014-Jan)

    ' http://social.msdn.microsoft.com/Forums/en-US
    ' /ccfa6998-9cc4-49c2-bd27-0d728fcd16da
    ' /password-strength-checker-program-help

    DefineASCIIBounds()

    TextWindow.Title = "Password Strength Checker"
    TextWindow.BackgroundColor = "DarkBlue"
    TextWindow.ForegroundColor = "Cyan"
    TextWindow.Clear()

    TextWindow.WriteLine("Type in a good password:")
    pass = TextWindow.Read()

    CheckPassStrength()
    JudgePassStrength()

    TextWindow.ForegroundColor = "Gray"
    TextWindow.Write(LF + "Password " + QT + pass + QT)
    TextWindow.WriteLine(" is " + verdict + "!" + LF)

    TextWindow.ForegroundColor = "Yellow"
    TextWindow.WriteLine("Upper  Letters ->  " + uppers)
    TextWindow.WriteLine("Lower  Letters ->  " + lowers)
    TextWindow.WriteLine("Number Digits  ->  " + digits)
    TextWindow.WriteLine("Other  Chars   ->  " + others)

    TextWindow.ForegroundColor = "Magenta"
    TextWindow.WriteLine(LF)

    Sub DefineASCIIBounds
     
      UPPER_A = Text.GetCharacterCode("A")
      UPPER_Z = Text.GetCharacterCode("Z")
     
      LOWER_A = Text.GetCharacterCode("a")
      LOWER_Z = Text.GetCharacterCode("z")
     
      NUM_0 = Text.GetCharacterCode(0)
      NUM_9 = Text.GetCharacterCode(9)
     
      LF = Text.GetCharacter(10)
      TB = Text.GetCharacter(9)
      QT = Text.GetCharacter(34)
     
    EndSub

    Sub CheckPassStrength
     
      uppers = 0
      lowers = 0
      digits = 0
      others = 0
     
      len = Text.GetLength(pass)
     
      For i = 1 To len
        code = Text.GetCharacterCode( Text.GetSubText(pass  i, 1) )
        
        If code >= UPPER_A And code <= UPPER_Z Then
          uppers = uppers + 1
        ElseIf code >= LOWER_A And code <= LOWER_Z Then
          lowers = lowers + 1
        ElseIf code >= NUM_0 And code <= NUM_9 Then
          digits = digits + 1
        Else
          others = others + 1
        EndIf
        
      EndFor
     
    EndSub

    Sub JudgePassStrength
     
      strength = 0
     
      If uppers > 0 Then
        strength = strength + 1
      EndIf
     
      If lowers > 0 Then
        strength = strength + 1
      EndIf
     
      If digits > 0 Then
        strength = strength + 1
      EndIf
     
      If others > 0 Then
        strength = strength + 1
      EndIf
     
      If strength = 0 Then
        verdict = "EMPTY"
      ElseIf strength = 1 Then
        verdict = "WEAK"
      ElseIf strength = 2 Then
        verdict = "MEDIUM"
      ElseIf strength = 3 Then
        verdict = "STRONG"
      Else
        verdict = "MIGHTY"
      EndIf
     
    EndSub

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Wednesday, January 29, 2014 11:47 PM
    Answerer