我在VB.NET中實現this,試圖使用實現方法here。無法訪問另一個類的枚舉
Dim score As Master.PasswordScore = Master.CheckStrength(txtPassVal)
的錯誤是::
Type 'Master.PasswordScore' is not defined.
下面是相關的全碼:我在這條線得到一個錯誤
大師班:
Public Enum PasswordScore
Blank = 0
TooShort = 1
RequirementsNotMet = 2
VeryWeak = 3
Weak = 4
Fair = 5
Medium = 6
Strong = 7
VeryStrong = 8
End Enum
Public Function CheckStrength(ByVal password As String) As PasswordScore
Dim score As Int32 = 0
If password.Length < 1 Then
Return PasswordScore.Blank
End If
If password.Length < 8 Then
Return PasswordScore.TooShort
End If
If password.Contains("password") Or password.Contains("12345678") Then
Return PasswordScore.RequirementsNotMet
End If
If password.Length >= 8 Then
score += 2
End If
If password.Length >= 12 Then
score += 1
End If
If Regex.IsMatch(password, "/\d+/", RegexOptions.ECMAScript) Then
'Contains a number
score += 1
End If
If Regex.IsMatch(password, "/[a-z]/", RegexOptions.ECMAScript) Then
'Contains a lowercase letter
score += 1
End If
If Regex.IsMatch(password, "/[A-Z]/", RegexOptions.ECMAScript) Then
'Contains an uppercase letter
score += 1
End If
If Regex.IsMatch(password, "/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", RegexOptions.ECMAScript) Then
'Contains special character
score += 2
End If
Return CType(score, PasswordScore)
End Function
使用另一班級的代碼:
Dim score As Master.PasswordScore = Master.CheckStrength(txtPassVal)
Dim i As Int32 = CType(score, Int32)
If i < 4 Then
lblMsg.Text = "Password does not meet minimum security requirements."
lblPasswordStrength.ForeColor = Drawing.Color.Red
Exit Sub
ElseIf i > 3 Then
lblPasswordStrength.ForeColor = Drawing.Color.DarkGreen
End If
lblPasswordStrength.Text = score.ToString()
它說它沒有被定義。有什麼理由不讓我訪問它?
是在同一個命名空間中的一切嗎? –
@MikeCheel我相信是這樣的,我在代碼中的其他地方調用Master的函數,並且它們工作正常。看起來,調用Enum就是問題。 – Dan