Password Generator help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sandspur
Posts: 2
Joined: 20 Feb 2011 22:12

Password Generator help

#1 Post by sandspur » 20 Feb 2011 22:17

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?

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Password Generator help

#2 Post by !k » 21 Feb 2011 01:32

You need 'endlocal'
...
Echo Enjoy your Password: !_RndAlphaNum!
endlocal
PAUSE
goto :Generate Password

sandspur
Posts: 2
Joined: 20 Feb 2011 22:12

Re: Password Generator help

#3 Post by sandspur » 21 Feb 2011 20:52

It worked!
Thank you so much!

Post Reply