我想创建一个密码生成器,它使用批处理方式生成一组预生成的密码。我正在尝试调整以下脚本。我希望系统使用前缀 LONDON 自动生成密码。我还希望有一个部分,我们可以在其中更改单词(如果可能)。有人可以帮忙吗?
此外,它需要从LONDON01
到LONDON100
。
@echo off
:Start2
cls
goto Start
:Start
title Welcome to my Password Generator
echo I will make you a new password.
echo Please write the password down somewhere in case you forget it.
echo ---------------------------------------------------------------
echo 1) 1 Random Password
echo 2) 5 Random Passwords
echo 3) 10 Random Passwords
echo Input your choice
set input=
set /p input= Choice:
if %input%==1 goto A if NOT goto Start2
if %input%==2 goto B if NOT goto Start2
if %input%==3 goto C if NOT goto Start2
:A
cls
echo Your password is %random%
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 Start2 if NOT goto Start 2
if %input%==2 goto Exit if NOT goto Start 2
:Exit
exit
:B
cls
echo Your 5 passwords are %random%, %random%, %random%, %random%, %random%.
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 Start2 if NOT goto Start 2
if %input%==2 goto Exit if NOT goto Start 2
:C
cls
echo Your 10 Passwords are %random%, %random%, %random%, %random%, %random%, %random%, %random%, %random%, %random%, %random%
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 Start2 if NOT goto Start 2
if %input%==2 goto Exit if NOT goto Start 2
答案1
如果您想要一个相当不错的“随机”,那么我建议使用 C++ 或其他程序(可以分发到您的办公系统)编写一个快速程序。但是,如果您遇到以下问题cmd
:
@echo off
set minimum=0
set maximum=100
set pre=LONDON
:A
set randnumber=%random%
if %randnumber% GEQ %minimum% (
if %randnumber% LEQ %maximum% (
echo %pre%%randnumber%
goto END
)
)
goto A
:END
输出示例:
调整以适应您的情况应该不会太难。
编辑:
作为补充,我想谈谈这个问题,就像其他人所说的那样:
这是一种极其不安全的生成密码的方式,除了锁定手机之外,实际上不应该用于任何其他用途,甚至不应该用于那样的情况。
真正的密码生成器应该具有为每个密码随机生成的“盐”,并且始终是唯一的。在中端计算机上,暴力破解您的密码集 (LONDON0 - LONDON100) 只需几秒钟。
相反,你可以使用 Python,例如:
import string, random
def genPass(prefix='LONDON', size=8, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits + '@!.&%$'):
return prefix + ''.join(random.choice(chars) for i in range(size))
print genPass()
这样可以为您设置更加随机或至少独特的密码。genPass(prefix='NOTLONDON', size=2)
例如,如果您想更改任何内容,只需拨打电话即可。
答案2
这应该可以修复您现有的批处理文件,使其可以正常工作。
@echo off
set "prefix=LONDON"
:Start2
cls
goto Start
:Start
title Welcome to my Password Generator
echo I will make you a new password.
echo Please write the password down somewhere in case you forget it.
echo ---------------------------------------------------------------
echo 1) 1 Random Password
echo 2) 5 Random Passwords
echo 3) 10 Random Passwords
echo Input your choice
set input=
set /p input= Choice:
if "%input%."=="." goto :Start
if %input%==1 goto A
if %input%==2 goto B
if %input%==3 goto C
goto :Start
:A
cls
echo Your password is %prefix%%random%
:reprompt1
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%."=="." goto :reprompt1
if %input%==1 goto Start2
if %input%==2 goto Exit
goto :reprompt1
:Exit
goto :EOF
rem exit
:B
cls
echo Your 5 passwords are %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%.
:reprompt5
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%."=="." goto :reprompt5
if %input%==1 goto Start2
if %input%==2 goto Exit
goto :reprompt5
:C
cls
echo Your 10 Passwords are %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%, %prefix%%random%
:reprompt10
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%."=="." goto :reprompt10
if %input%==1 goto Start2
if %input%==2 goto Exit
goto :reprompt10
如果您需要不同的东西,请告诉我。
编辑:
我刚刚注意到评论表明你需要结果在LONDON01
到LONDON100
,因此我修改了批处理文件来执行以下操作:
@echo off
set "prefix=LONDON"
:Start2
cls
goto Start
:Start
title Welcome to my Password Generator
echo I will make you a new password.
echo Please write the password down somewhere in case you forget it.
echo ---------------------------------------------------------------
echo 1) 1 Random Password
echo 2) 5 Random Passwords
echo 3) 10 Random Passwords
echo Input your choice
set input=
set /p input= Choice:
if "%input%."=="." goto :Start
if %input%==1 goto A
if %input%==2 goto B
if %input%==3 goto C
goto :Start
:A
cls
call :getpws 1
call :showpws 1
:reprompt1
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%."=="." goto :reprompt1
if %input%==1 goto Start2
if %input%==2 goto Exit
goto :reprompt1
:Exit
set "pw1="
set "pw2="
set "pw3="
set "pw4="
set "pw5="
set "pw6="
set "pw7="
set "pw8="
set "pw9="
set "pw10="
set "pwcount="
set "pwindex="
set "pwmessage="
set "pwresult="
goto :EOF
rem exit
:B
cls
call :getpws 5
call :showpws 5
:reprompt5
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%."=="." goto :reprompt5
if %input%==1 goto Start2
if %input%==2 goto Exit
goto :reprompt5
:C
cls
call :getpws 10
call :showpws 10
:reprompt10
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%."=="." goto :reprompt10
if %input%==1 goto Start2
if %input%==2 goto Exit
goto :reprompt10
:getpws
set pwcount=%~1
rem this step (clear) not totally necessary...
call :clearallpws
for /L %%f in (1,1,%pwcount%) do call :get1pw %%f
goto :EOF
:clearallpws
for /L %%f in (1,1,10) do call :clearpw %%f
goto :EOF
:clearpw
rem clear password numbered by %1
set pwindex=%~1
for /F "usebackq delims=" %%g in (`echo set "pw%pwindex%="`) do %%g
goto :EOF
:get1pw
set pwindex=%~1
rem get a random number, add a leading 0 to make sure it is at least 2 digits long
set pwresult=0%random%
rem keep the last two digits
set "pwresult=%pwresult:~-2,2%"
rem this will now be something from 00 to 99
rem now add 1
set /a pwresult+=1
rem this will now be a number from 1 to 100. Add leading "0" for numbers below 10
if %pwresult% LEQ 9 set "pwresult=0%pwresult%"
rem this will now be a number from 01 to 100. Insert the prefix
set "pwresult=%prefix%%pwresult%
rem now assign it to pw(n) variable. and return
for /F "usebackq delims=" %%g in (`echo set "pw%pwindex%=%pwresult%"`) do %%g
goto :EOF
:showpws
set pwcount=%~1
set "pwmessage=Your %pwcount% passwords are: %pw1%"
if %pwcount% EQU 1 set "pwmessage=Your password is: %pw1%"
for /L %%g in (2,1,%pwcount%) do call :append1pw %%g
echo %pwmessage%
goto :EOF
:append1pw
set pwindex=%~1
for /F "usebackq delims=" %%h in (`echo set "pwmessage=%pwmessage%, %%pw%pwindex%%%"`) do %%h
goto :EOF
答案3
命名空间:System.Web.Security;GeneratePassword 方法
您需要在 powershell 中启用 .Net 4:
查看powershell主路径:
powershell $pshome
进入 powershell 主目录:
cd %windir%\system32\WindowsPowerShell\v1.0
编辑
powershell.exe.config
并powershell_ise.exe.config
:
<?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0.30319"/> <supportedRuntime version="v2.0.50727"/> </startup> </configuration>
命令行:
powershell [Reflection.Assembly]::LoadWithPartialName('System.Web')^|Out-Null;1..12^|%{[System.Web.Security.Membership]::GeneratePassword(16,3)}
输出:
}=+TW7Nsq?W(7Pr=
H@^*WKxH{S._79-d
y5Ls@ii+[P;3&P{3
^B%3eBHo|2V!Q{UW
2$(F8;s9prwURA#c
dZ*k(e(F_C%XJv-}
#SP9La)sWBhVh][Z
u7^d3U36N@66vSe+
Z.hH0e$Z/Jdb4CHs
XxkZTxJr.t(|QHn&
C+qOCz2G(MpGZF)W
06ZY&q^E/z9K5cKD
简单密码,命令行:
powershell 1..12^|%{$i='';1..7^|%{$i+=[char](Get-Random -min 65 -max 90)};1..2^|%{$i+=(Get-Random -min 10 -max 99)};echo $i}
输出:
VCXJNCA7249
MUIFGHV8240
YOVGWPH8556
FGOEEFR7862
SWOOAQS8714
OLHYSFW4985
WOEHCRN8249
VHPDMLR1991
TKOEMBO7344
FFMJGSJ8325
KLUVAEF8960
LKYVHQH2212
简单密码,变体 2,命令行:
powershell 1..3^|%{$i='LONDON-';1..4^|%{$i+=[char](Get-Random -min 65 -max 90)};$i+='-'+(Get-Random -min 1001 -max 9999);echo $i}
输出:
LONDON-UCUT-3323
LONDON-CCCB-5950
LONDON-SNFX-9316