这批密码生成如何工作?

时间:2017-12-19 14:49:18

标签: batch-file

我正在批量创建密码生成器,并且必须使用来自互联网的一些帮助才能完成它,但是我很难解释我必须借用的代码部分。有人请解释一下吗?

:generate
@Echo Off
color 0a
set /P usernumberlength="What length do you want your password to be?   "
pause
cls
Setlocal EnableDelayedExpansion
Set RNDLength=%usernumberlength%

///从这里

Set Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set Str=%Alphanumeric%987654321
:loop
IF NOT "%Str:~18%"=="" SET Str=%Str:~9%& SET /A Length+=9& GOTO :loop
SET tmp=%Str:~9,1%
SET /A Length=Length+tmp
Set count=0
SET RndAlphaNum=
:loop2
Set /a count+=1
SET RND=%Random%
Set /A RND=RND%%%Length%
SET RndAlphaNum=!RndAlphaNum!!Alphanumeric:~%RND%,1!
If !count! lss %RNDLength% goto loop2

///到这里

Echo Password is: is !RndAlphaNum!
Echo Now choose what you want to do.
Echo 1) Go back to the beginning
Echo 2) Exit
set input=
set /p input= Choice:
if %input%==1 goto generate
if %input&==2 exit

pause

1 个答案:

答案 0 :(得分:0)

此工作示例(来自您提供的代码)包含所有您需要的部分。

@echo Off
color 0a
setlocal enabledelayedexpansion

:generate
set /p usernumberlength="What length do you want your password to be? "

rem ----- begin section all you need -----
Set Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

rem "Length" is the string length of %alphanumeric%
Set Length=62
set count=0
rem "RndAlphaNum" is the output
SET RndAlphaNum=

:loop
Set /a count+=1
Set /A RND=%Random% %% %Length%
SET RndAlphaNum=!RndAlphaNum!!Alphanumeric:~%RND%,1!
if !count! lss %usernumberlength% goto loop
rem ----- end section all you need -----

echo Password is: !RndAlphaNum!
goto generate