how do you make a letter password generator in batch?
I'm having a hard time figuring out how to make a password generator with random letters in it. For example, ASWED-ASDWAD-EFEST. So far I can only make random numbers by using the code
@echo off
:password
echo %random%-%random%-%random
pause
goto password
PS: my OS is windows vista.
all help will be appreciated.
There is a discussion here that you could adapt for your purposes.
@Echo Off
Setlocal EnableDelayedExpansion
Set _RNDLength=8
Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set _Str=%_Alphanumeric%987654321
:_LenLoop
IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
SET _tmp=%_Str:~9,1%
SET /A _Len=_Len+_tmp
Set _count=0
SET _RndAlphaNum=
:_loop
Set /a _count+=1
SET _RND=%Random%
Set /A _RND=_RND%%%_Len%
SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
If !_count! lss %_RNDLength% goto _loop
Echo Random string is !_RndAlphaNum!
TheOutcaste explains the above:
I've modified it so you can easily specify the length and add or remove characters without having to change any other part of the code.
For example, you might not want to use both 0 and O (zero and Uppercase O), or 1 and l (one and lowercase L).
You can use punctuation except for these characters:
! % ^ & < >
You can use
^
and%
, but must enter them in the_Alphanumeric
variable twice as ^^ or%%
. However, if you want to use the result (_RndAlphaNum
) later in the batch file (other than Echoing to the screen), they might require special handling.You can even use a space, as long as it's not the last character in the string. If it ends up as the last character in the generated string though, it will not be used, so you would only have 7 characters.
rem 16 stings pwd
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set alfanum=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
set pwd=
FOR /L %%b IN (0, 1, 16) DO (
SET /A rnd_num=!RANDOM! * 62 / 32768 + 1
for /F %%c in ('echo %%alfanum:~!rnd_num!^,1%%') do set pwd=!pwd!%%c
)
echo pwd=%pwd%
This is a simple and elegant solution to this
@echo off
setlocal enableextensions enabledelayedexpansion
set /P _length=Password Length: %==%
set /a z = %_length%
set "string=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
set "password="
for /L %%i in (1,1,!z!) do call :_genRand
echo Password is: %password%
goto :EOF
:_genRand
set /a x=%random% %% 62
set password=%password%!string:~%x%,1!
goto :eof