2013-11-27 1 views
1

배열을 추가 할 때 마스크를 어떻게 사용할 수 있는지 잘 모르겠습니다. 또한 마스킹 시스템이 백 스페이스를 문자로 인식하지 못하게하고 싶습니다. 높이 평가 로그인 시스템에서 마스킹 시스템을 어떻게 해석 할 수 있습니까?

Module Module1 

Sub Main() 

    Dim memofs As Char 
    Dim stdntpassword As String = Nothing 
    Dim staffpassword As String = Nothing 
    Console.Write("Are you a member of staff? (y/n) ") 
    memofs = Console.ReadLine 
    If memofs = "y" Or memofs = "Y" Then 

    ElseIf memofs = "n" Or memofs = "N" Then 
     Console.WriteLine("Password: ") 
     stdntpassword = Console.ReadLine 
    End If 

    For attempts As Integer = 1 To 5 

     Console.WriteLine() 
     Console.WriteLine("Attempt Number " & attempts) 
     Console.WriteLine() 
     Console.Write("Password: ") 
     staffpassword = Console.ReadLine 
     Dim fullline As String = "" 
     FileOpen(1, _ 
      "E:\Computing\Spelling Bee\StaffPasswords\staffpassword.csv", OpenMode.Input) 
     fullline = LineInput(1) 
     Dim item() As String = Split(fullline, ",") 
     If staffpassword = item(0) Then 
      Console.Clear() 
      staffmenu() 
     Else : FileClose(1) 
     End If 
     Console.Clear() 

,

답변

3

내가 전에 한 번 이런 짓을, 대신에 암호를 마스킹 한은, 별표, 난 그냥 빈 (리눅스에 암호를 입력 등)을 왼쪽 말한다. 후자는 매우 간단합니다 :

Dim keyInfo as ConsoleKeyInfo = Console.ReadKey(True) 
Dim enteredPassword as String = "" 
' Read each entered character until user presses Enter. 
While keyInfo.Key <> ConsoleKey.Enter 
    If keyInfo.Key = ConsoleKey.Backspace AndAlso enteredPassword.Length > 0 Then 
     enteredPassword = enteredPassword.Substring(0, enteredPassword.Length - 1) 
    Else 
     password &= keyInfo.KeyChar 
    End If 
    ' Read next entered character 
    keyInfo = Console.ReadKey(True) 
End While 

실제로, 비밀번호 입력 마스크 같은 생각을 사용하지만, 문자를 입력 할 때마다 구문 분석 후하는 Console.Write("*"c)을 추가하려면. 이 리스팅 백 스페이스와 조금 까다로운, 그리고 내가 알고있는 유일한 방법은 그것을 할 것 시뮬레이션 :

Console.Write(ControlChars.Back)' move cursor back one column 
Console.Write(" "c) ' clear the asterisk 
Console.Write(ControlChars.Back)' move cursor back again to allow writing. 

그것은 내 의견으로는 C#에서 조금 더 예쁜 (그리고 대신 ControlChars.Back'\b'을 사용하여 작동) 때문에 결과를 다를 수 있습니다.

더 쉬운 방법이 있다면, 은 (는)을 사랑합니다. 이것은 매우 간단한 작업을 위해 바퀴를 다시 만드는 것처럼 보입니다.

+0

당신은 남자입니다! 고마워요! – user3042666

0

post은 좋은 예를 보여줍니다. 백 스페이스 및 다시 실행 기능으로 마스킹을 수행합니다.