China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 00:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Repost] Random Password Generation View 1,265 Replies 4
Original Poster Posted 2010-09-08 11:59 ·  中国 江苏 苏州 张家港市 电信
初级用户
Credits 47
Posts 23
Joined 2006-09-27 20:54
19-year member
UID 63820
Status Offline
I've been learning batch files lately, and came across a pretty good little thing for randomly generating passwords.
Reposting it here to share~
It uses quite a lot of commands. For someone at my level, I feel every bit of it is gold, and it really needs to be understood line by line.


@echo off
call :randomPassword 8 pass1
echo %pass1%
pause
exit
:randomPassword
::---------generate random password
::---------%1 is the password length, %2 and after are the names of the return variables
::---------goto loop, nested variables, nested commands
@echo off
if "%1"=="" goto :eof
if %1 lss 1 goto :eof
set password_len=%1
set return=
set wordset=abcdefghijklmnopqrstuvwxyz023456789_
::---------------------------loop
:randomPassword1
set /a numof=%random%%%36
call set return=%return%%%wordset:~%numof%,1%%
set /a password_len-=1
if %password_len% gtr 0 goto randomPassword1
::---------------------------loop
if not "%2"=="" set %2=%return%
shift /2
if not "%2"=="" goto randomPassword
Floor 2 Posted 2010-09-08 12:26 ·  中国 广东 韶关 电信
高级用户
★★★
CMD感染者
Credits 691
Posts 383
Joined 2008-05-23 00:38
18-year member
UID 119451
Gender Male
Status Offline
I suggest using the CODE tag.
Floor 3 Posted 2010-09-08 15:37 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
For someone at my level, I feel every bit of it is gold, and it really needs to be understood line by line.

Mm, if you have time, just read more tutorials.
Floor 4 Posted 2010-09-10 13:01 ·  中国 辽宁 葫芦岛 联通
中级用户
★★
Credits 247
Posts 147
Joined 2009-04-09 20:52
17-year member
UID 142531
Gender Male
Status Offline
Hehe, interesting.
Randomly picks %1 characters from a-z 0-9 _, then combines them as the password.

If you add A-Z, wouldn't that be even more perfect?

Can't you use for instead of a goto loop?

[ Last edited by DXSX on 2010-9-10 at 13:44 ]
Floor 5 Posted 2010-09-18 11:47 ·  中国 上海 移动
新手上路
Credits 8
Posts 8
Joined 2010-09-15 21:20
15-year member
UID 174259
Gender Male
From 上海
Status Offline
Ahem... moderator... where is the tutorial on setting %1~9 parameters?...
Forum Jump: