我怎样才能跨preT在我登录系统掩蔽系统? [英] How can I interpret a masking system in my login system?
问题描述
我只是不知道我怎么可以通过添加阵列的面具。我也想掩蔽系统识别退格不是一个字母。
I'm just not sure how I can mask with the addition of arrays. I would also like the masking system to recognize backspace not as a letter.
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()
鸭preciated,
Appreciated,
推荐答案
我曾经这样做过,但不是掩蔽密码,说一个星号,我刚刚离开它留空(如进入Linux的密码) 。后者是pretty简单:
I've done this once before, but instead of masking the password with, say an asterisk, I just left it blank (like entering a password in Linux). The latter is pretty straightforward:
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是一个有点棘手与退格,我知道的唯一办法模拟它会做的:
To actually mask the password input, use the same idea, but after each character is entered and parsed, add a Console.Write("*"c)
. This get's a bit tricky with backspace, and the only way I know to simulate it would be to do:
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#中位prettier在我看来,(和作品使用'\\ B'
而不是 ControlChars.Back
),因此您的结果可能会有所不同。
It's a bit prettier in C# in my opinion (and works using '\b'
instead of ControlChars.Back
) so your results may vary.
此外,如果有这样做一个简单的方法,我的爱的知道,因为这似乎是重新发明轮子一个相当简单的任务。
Also if there's an easier way to do this, I'd love to know, as this seems like reinventing the wheel for a fairly simple task.
这篇关于我怎样才能跨preT在我登录系统掩蔽系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!