Page 1 of 1

Password Generator help

Posted: 20 Feb 2011 22:17
by sandspur
Alright, so I've made a pretty powerful password generator, but there is one issue: when the process restarts, instead of generating a 8-character code, it generates a 4,3,2,1 or even 0 character code. Here's the source code:

Code: Select all

@Echo Off
:Generate Password
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 Enjoy your Password: !_RndAlphaNum!
PAUSE
goto :Generate Password
What's causing it to decrease?

Re: Password Generator help

Posted: 21 Feb 2011 01:32
by !k
You need 'endlocal'
...
Echo Enjoy your Password: !_RndAlphaNum!
endlocal
PAUSE
goto :Generate Password

Re: Password Generator help

Posted: 21 Feb 2011 20:52
by sandspur
It worked!
Thank you so much!