批量制作密码 [英] Batch Making Passwords
问题描述
我已经做了一批游戏,用户可以登录/注册。但在有密码,如果站在附近的人可以在窥视密码没有意义。普通密码字段屏蔽字符星号(*)。
I have made a batch game where users can log in / register. But there is no point in having passwords if a person standing nearby can peep at the password. Normal password fields mask the characters with asterisks (*).
如何能在一个批处理文件掩码字符?
How can mask characters on a batch file?
我已经看到了这个工作之前CMD,但我不知道怎么样。
I've seen this done on cmd before but I have no clue how.
推荐答案
好吧,这是你可能心里有一点不同,但是这是你为游戏开发者选择批量故障。
Ok, this is a bit different to what you may have had in mind, but that's you're fault for choosing batch for game dev.
我看事情是这样的,你有3个选项:
The way I see it is you have 3 options:
- 使用您自身在C#中作了一个外部程序,C ++,Python和[等]
- Howver这需要一个应用为你已经做到这一点(这有可能是),或者对你有知识,这些语言中的一种
- 然而,这限制了密码字符选择,使得程序看起来很丑陋
- 这可能是有时有点dodgey,在会有点复杂,但可能是你唯一的选择。
现在,因为我打字这一点的想法卡住我的如何实现这一头。因为它可能需要一些时间来检验,我想我会发布这个想法(因为它似乎是一个soloution这个问题,这已经有一段时间了)。
Now, as I was typing this an idea stuck my head on how to achieve this. Since it might take some time to test I thought I'd post the idea (as it seems to be a soloution to this problem, which has been around for a while).
- 一批线程将简单地使用
设置/ P
来所有输入存储到一个变量,完成之后将通过使用<$ C的传达给其他批次线$ C> WAITFOR 或一个简单的目录文件。 - 又一批的线程将循环
暂停&GT; NUL
语句,并会相符的次数暂停
语句循环播放,打印出*
的适量。该线程的其他重要的工作是要感测当用户已经完成输入密码时,在其它退出。
- One Batch Thread will simply use
set /p
to store all the input into a variable and upon completion will communicate to the other batch thread through the use ofwaitfor
or a simple directory file. - Another Batch Thread would loop the
pause >nul
statement and would tally the number of times thepause
statement is looped, printing out the appropriate amount of*
's. The other important job of this thread is to sense when the user has finished typing the password, upon which it exits.
即时通讯开始做这个批处理程序了,但现在我只想让你到目前为止告诉我的想法。
Im starting to make this batch program now, but for now I'll just keep you informed of my idea so far.
@echo off Title Password Please: :: This is the main code REM This code relies on Masker.bat REM SET password to be first and thrid letter, REM of the day of the week. set pass=%Date:~0,1%%Date:~2,1% REM START Masker in the same window using /b tag and create hold.pass: Echo 0 >%temp%\hold.pass start /b Masker.bat "%pass%" * REM Simply take input an leave the rest to Masker.bat set /p pass_input=: Echo 1 >>%temp%\hold.pass cls if /i "%pass%" NEQ "%pass_input%" ( Title Worng Password Echo Wrong Password... Sorry. Sleep 5 Exit ) Pause > nul REM Rest of Main game code is below or simply :: START Main.bat & Exit
Masker.bat
@echo off Title Password Please: setlocal enabledelayedexpansion :: This is not the main code REM This code is called upon by Login.bat (or the Main.bat game code) REM CREATE the variables "passlen" and "mask": set password=%~1 set passlen=0 :miniloop set /a passlen+=1 if "!password:~%passlen%,1!" NEQ "" goto :miniloop set password= set mask=%~2 if "%mask%" EQU "" set mask=* REM MAIN loop :loop cls for /l %%a in (1,1,%passlen%) do (<nul set /p=%mask%) sleep -m 150 for /f "usebackq" %%a in ("%temp%\hold.pass") do (if "%%~a" EQU "1" Del %temp%\hold.pass & Exit) goto :loop
它仍然需要更多的改进,但我已经花了aroung 30分钟就可以了,但收效甚微,使其动态地告诉你,你有多少个字符输入。
It still needs some more improvements, but I've spent aroung 30 min on it with little success to make it dynamically tell you how many characters you have typed in.
任何甘蔗借此起来,是我的客人。其他一切工作正常。
Anyone cane take this up, be my guest. Everything else works fine
蒙娜丽莎
这篇关于批量制作密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!