Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a batchfile that creates users on a proxy server. You enter a username and a password, which pretty much is just randomly slamming keys up to 8 characters.
Is there a way to make dos generate this? %random% could work, except that its just numbers and I want numbers and lowercase letters, to form a completely randomized string of 8 characters.

The folowing is not a true random password, but you can build on it replacing the conditional statement
@Echo Off
SetLocal EnableDelayedExpansion
Set Alpha=abcdefghijklmnopqrstuvwxyzFor /L %%j in (1,1,8) Do Call :PSW
Echo Password is [%PSWRD%]
EndLocal
GoTo :EOF:PSW
If %random% gtr 10000 (
Set PSWRD=%PSWRD%%random:~0,1%
) else (
Set /A i=%random:~-1,1%+%random:~1,1%
If !i! gtr 25 Set i=25
Set PSWRD=%PSWRD%!Alpha:~%i%,1!
)
GoTo :EOF

The number of digits/characters in the string is driven by
For /L %%j in (1,1,8) Do Call :PSW
so to get a key of 2 digits code
For /L %%j in (1,1,2) Do Call :PSW
Beware the sample posted is a raw one; it may return a numeric key as an alphameric one. To meet high safety standard more work is required.

Sorry I I did not understand what actually you want, i.e. to generate a key with two digits only, isn't it?
To achieve that replace the :PSW routine with
:PSW
If "%Digit%"=="2" Goto :CHR
If %random% gtr 10000 (
Set PSWRD=%PSWRD%%random:~0,1%
Set /A Digit+=1
GoTo :EOF)
:CHR
Set /A i=%random:~-1,1%+%random:~0,1%
Set /A i=%i%+%random:~-1,1%
If !i! gtr 25 Set i=25
Set PSWRD=%PSWRD%!Alpha:~%i%,1!
GoTo :EOFThat has minor fixes too.

What I actually want is a random string of 8 characters formed by lowercase letters and a maximum of 2 numbers. So something like
wehy10wnw
2y8wejabfThe position of the numbers should be random too. So exactly that! Thanks!
How does it do what it does?

From your last post I assumed my code works and fits your needs (I did not test the improved script I posted as I was short in time).
The batch relies on the "delayed expansion of variables" that allows to manipulate substrings and array variables, as Alpha, using the "variable inside variable" notation (! and % to mark variables).
The whole script is actually a strechted implementation of advanced NT batch coding.

I see.
How do I implement this in my code?
In the current situation it asks for a user and a pass which it then exports to a text file. What I want it to do is that when the string entered for the pass is "x" it generates a password and exports that with the user name.

Mail me at the address you find clicking IVO and report *exactly* what your batch needs to do.My code can easily be integrated into your script, but I prefer the private mail channel because this thread is fading down as time goes by.
And you have to be patient before getting an answer as I have my own business to run too.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |