我试图从 youtube 运行密码生成器。 这是代码:
@echo off
chcp 1257
setlocal EnableDelayedExpansion
set alpha=
aąbcčdeęėfghiįjklmnopqrsštuųūvwxyzžAĄBCČDEĘĖFGHIĮJKLMNOPQRSŠTUŲŪVWXYZŽ
For /L %%j in (1,1,13) DO CALL:GEN
echo Your Random Password is [ %PASSWORD% ]
EndLocal
pause
:GEN
For /L %%j in (1,1,10) DO (
if %random% gtr 10000 ( set PASSWORD=%PASSWORD%%random:~0,1% ) else (
set /a i=%random:~1,1%+%random:~1,1%
if !i! gtr 25 set i=25
set PASSWORD=%PASSWORD%!alpha:~%i%,1! )
)
这将返回 1 个随机密码。我需要 10 个密码,所以我尝试在这一行之前创建 for 循环: For /L %%j in (1,1,13) DO CALL:GEN 。然后它返回 10 行文本但没有密码:
Active code page: 1257
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Your Random Password is [ ]
Press any key to continue . . .
我该如何解决这个问题?
@echo off & setlocal EnableDelayedExpansion
chcp 1257
set "alpha=aabccdeeefghiijklmnopqrsštuuuvwxyzžAABCCDEEEFGHIIJKLMNOPQRSŠTUUUVWXYZŽ"
set alphaCnt=70
For /L %%j in (1,1,10) DO CALL :GEN %%j
pause
Goto :Eof
:GEN
Set "Password="
For /L %%j in (1,1,10) DO (
Set /a i=!random! %% alphaCnt
Call Set PASSWORD=!PASSWORD!%%alpha:~!i!,1%%
)
echo Your Random Password %1 is [%PASSWORD%]
样本输出:
Your Random Password 1 is [EÜllxleUOc]
Your Random Password 2 is [RBGEoÄulEF]
Your Random Password 3 is [AfuuAEFwMe]
Your Random Password 4 is [kuaEjuLicr]
Your Random Password 5 is [ModgGsANÄE]
Your Random Password 6 is [MzEqSWJWCB]
Your Random Password 7 is [oÜcrFUqGpj]
Your Random Password 8 is [kRHDCqiciÜ]
Your Random Password 9 is [gUYjjSiicQ]
Your Random Password 10 is [cuuAOÜixVY]
试试这个。您可以向
alp
变量添加/删除字符。
@echo off
setlocal enabledelayedexpansion
set "alp=@ # ^& % a A b B c C d D E e f F g G h H I I j J k K l L m M n N p P q Q r R s S t T u U v V w W x X y Y z Z 0 1 2 3 4 5 6 7 8 9"
set "cnt=0"
for %%a in (%alp%) do (
set "rn.!cnt!=%%a"
set /a "cnt+=1"
)
for /l %%i in (1,1,10) do (
set "pssw="
for /l %%a in (1,1,13) do (
set /a "rand=!random! %% cnt"
for %%b in (!rand!) do set "pssw=!pssw!!rn.%%b!"
)
echo Your random password is: [ !pssw! ]
)
请注意,您不能使用
!
作为字符,因为我们在这里使用 delayedexpansion
。