Created
June 21, 2020 13:21
-
-
Save dolphinotaku/f689d1bef7d7ba76c7f71dad42e2987d to your computer and use it in GitHub Desktop.
this batch script generate a password include at least 1 upper letter, 1 lower letter, 1 numeric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: to generate a 10 length password use below in .bat | |
:: call gen_pwd.bat 10 | |
@echo off | |
setlocal enableextensions enabledelayedexpansion | |
set "lower=abcdefghijklmnopqrstuvwxyz" | |
set "upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
set "numeric=0123456789" | |
set "alphanumeric=%lower%%upper%%numeric%" | |
set "pwdLength=%1" | |
set /a part1=1 | |
set /a part2=%part1%+1 | |
set /a part3=%pwdLength%-%part2% | |
set "result=" | |
set /a index = 1 | |
for /L %%i in (1,1,%pwdLength%) do ( | |
if !index!==1 ( | |
call :addUpper | |
) else if !index!==2 ( | |
call :addNumeric | |
) else if !index!==3 ( | |
call :addLower | |
) else ( | |
call :addAny | |
) | |
set /a index+=1 | |
) | |
@echo %result% | |
endlocal | |
goto :eof | |
:addUpper | |
set /a u=%random% %% 25 + 1 | |
set result=%result%!upper:~%u%,1! | |
goto :eof | |
:addLower | |
set /a u=%random% %% 25 + 1 | |
set result=%result%!lower:~%u%,1! | |
goto :eof | |
:addNumeric | |
set /a n=%random% %% 9 + 1 | |
set result=%result%!numeric:~%n%,1! | |
goto :eof | |
:addAny | |
set /a s=%random% %% 61 + 1 | |
set result=%result%!alphanumeric:~%s%,1! | |
goto :eof | |
:: Batch file: random alphanumeric sequence | |
:: https://stackoverflow.com/questions/46573603/batch-file-random-alphanumeric-sequence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment