2013-11-27 55 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

我曾經這樣做過,但不是以掩蓋密碼,說一個星號,我剛剛離開它留空(如在Linux中輸入密碼)。後者是非常簡單的:

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)。這GET是一個有點棘手與退格,我知道只有這樣,才能模擬它會做的事:

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#有點漂亮,我認爲(和工程使用'\b'代替ControlChars.Back),因此您的結果可能會有所不同。

此外,如果有一個更簡單的方法來做到這一點,我會知道,因爲這似乎是重塑一個相當簡單的任務的車輪。

+0

你是男人!非常感謝你! – user3042666

0

這個post有一個很好的工作例子給你。它具有屏幕退格和重做支持。