VB.NET 2008/VB - 문자열

문자열 - 암호의 복잡성 검사

본클라쓰 2011. 4. 8. 09:30

암호는 사용자 인증을 위해 보안 시스템에서 사용될 수 있는데 이때 인증되지 않은 사용자가 추측하기 어려운 암호를 사용해야 한다. 공격자는 딕셔너리 공격 프로그램을 사용하여 일반 사전이나 다양한 언어로 되어 있는 여러 사전에 있는 모든 단어를 반복하면서 어떤 단어가 사용자 암호로 사용되는지 테스트할 수 있다.

 

"Yankees" 또는 "Mustang"과 같이 강력하지 않은 암호는 빨리 추측될 수 있다. ?You'L1Noiwjf"와 같은 강력한 암호는 훨씬 추측하기 어렵다. 암호 보호 시스템은 사용자가 강력한 암호를 선택했는지 확인해야 한다.

 

강력한 암호는 대문자, 소문자, 숫자 그리고 특수 문자가 혼합된 복합어이며 한 단어가 아니다. 이 예제는 복합성을 확인하는 방법을 보여준다.

 

Function Validatepasswor(ByVal pwd As String, _

    Optional ByVal minLength As Integer = 8, _

    Optional ByVal numUpper AS Integer = 2, _

    Optional ByVal numLower As Integer = 2, _

    Optional ByVal numNumbers As Integer = 2, _

    Optional ByVal numSpecial As Integer = 2) As Boolean

 

    ' Replase [A-Z] with \p{Lu}, to allow for unicode uppercase letters.

    Dim upper As New System.Text.Regularexpressions.Regex("[A-Z]")

    Dim lower As New System.Text.Regularexpressions.Regex("[a-z]")

    Dim number As New System.Text.Regularexpressions.Regex("[0-9]")

    ' Special is "none of the above"

    Dim special As New System.Text.Regularexpressions.Regex("[^a-zA-Z0-9]")

 

    ' Check the length

    If Len(pwd) < minlength Then return False

 

    ' Check for minimum number of occurrences.

    If upper.Matchs(pwd).Count < numUpper Then Return False

    If lower.Matchs(pwd).Count < numLower Then Return False

    If number.Matchs(pwd).Count < numNumbers Then Return False

    If special.Matchs(pwd).count < numSpecial Then Return False

 

    ' Passed all Checks.

    Return True

 

End Function

 

 

네트워크를 통해 암호를 이동하는 경우 데이터 전송에 안전한 방법을 사용해야 한다.