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-07-04 20:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to store passwords in an encrypted manner for batch processing to call? View 3,661 Replies 11
Original Poster Posted 2011-01-10 23:57 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 400
Posts 211
Joined 2007-09-30 18:02
18-year member
UID 98650
Gender Male
Status Offline
How to store passwords encrypted for calling during batch processing?

[ Last edited by uiopuiop on 2011-1-10 at 23:58 ]
Floor 2 Posted 2011-01-11 00:35 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
What are the password rules? Pure numbers? Numbers plus letters? Or common characters? What are the requirements for the encryption algorithm? Where is the storage location specified? In the registry or a file?
Floor 3 Posted 2011-01-11 01:13 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
I wrote a simple one, the password requirement is pure numbers, saved in the registry:
@echo off&setlocal enabledelayedexpansion
set x0=!random!!random!!random!!random!!random!&echo !x0! original
set r=hkcu\Software\hanye

:x1: encryption algorithm
if not "!x0:~%n%,1!"=="" set/a a=!x0:~%n%,1!+!n:~-1!,n+=1&set x1=!x1!!a:~-1!&goto:x1
echo %x1% encrypted
reg add %r% /ve /d %x1% /f>nul

for /f "tokens=3 delims=这里是制符" %%a in ('reg query %r% /ve') do set x3=%%a
:x2: decryption algorithm
if not "!x3:~%m%,1!"=="" set/a a=1!x3:~%m%,1!-!m:~-1!,m+=1&set x2=!x2!!a:~-1!&goto:x2
echo %x2% decrypted

pause
reg delete %r% /f>nul


[ Last edited by Hanyeguxing on 2011-1-11 at 01:54 ]
Floor 4 Posted 2011-01-11 19:27 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 400
Posts 211
Joined 2007-09-30 18:02
18-year member
UID 98650
Gender Male
Status Offline
Originally posted by Hanyeguxing at 2011-1-11 12:35 AM:
What are the password rules? Pure numbers? Numbers plus letters? Or common characters?
What are the requirements for the encryption algorithm?
Where is the storage location specified? In the registry or in a file?


re: What are the password rules? - A mix of letters and numbers (of course, it would be better if special symbols can be included)
re: What are the requirements for the encryption algorithm? - Generally, it should be not easy to crack. Of course, if a more advanced encryption can be used (MD5, DSA, RSA, etc.)

re; Where is the storage location specified? It is best to store it in a file.

Batch processing can call third-party command-line tools.

PS. Can you explain the encryption principle of the code on the third floor, thank you!
Floor 5 Posted 2011-01-12 13:43 ·  中国 北京 263网络通信电信数据中心
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Add more, remove the if...

The written bat code, most of the core operations rely on the password.

Then encrypt the password with MD5 and compare it in the bat. If correct, execute...

So if you see your bat source code, if there is no comparison, a random password is not acceptable.

set password=
if md5(password)=fde3494783dfd854

The core part of the operation is all related to %password%, some character in the middle, some character is re-operated and deformed...

Only when there is no correct password and skip the judgment and execute next can it not work.
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 6 Posted 2011-01-12 23:37 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 400
Posts 211
Joined 2007-09-30 18:02
18-year member
UID 98650
Gender Male
Status Offline
Originally posted by slore at 2011-1-12 01:43 PM:
Add more, cancel the if...

The written bat code, most core operations depend on the password.

Then encrypt the password with MD5 and compare it in the bat. If it is correct, execute...

So seeing your...


Generally, automated scripts run automatically without manual intervention, so there can be no manual input of the password.
After you encrypt with MD5, how do you decrypt it? The password must be in plain text when the batch processing runs. When running, it must be decrypted and then passed to the corresponding command. MD5 cannot recognize it.
Floor 7 Posted 2011-01-12 23:53 ·  中国 广东 深圳 电信
新手上路
Credits 5
Posts 9
Joined 2008-08-28 10:30
17-year member
UID 124367
Gender Male
Status Offline
Great! I'm a newbie! So I can only watch and can't contribute much.
Floor 8 Posted 2011-01-13 09:54 ·  中国 北京 263网络通信电信数据中心
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Originally posted by uiopuiop at 2011-1-12 23:37:


Most automated scripts run automatically without manual intervention, so passwords cannot be entered manually.
After you encrypt with MD5, how do you decrypt it? The password must be in plain text when the batch file runs. It must be decrypted and then passed to the corresponding command during execution. MD5 can't recognize it.



You don't set a password if you want no intervention...


Here, plain text is entered using set /p pw=

Then calculate MD5 and compare it with the MD5... There is a relationship with the password you entered through the following operations, so an incorrect password cannot be used.


If you simply set a password and just read it automatically? Automatically judge...
If you comment out the judgment, what encryption do you have?
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 9 Posted 2011-01-13 21:34 ·  中国 广东 东莞 中移铁通
初级用户
★★
Credits 115
Posts 92
Joined 2010-12-24 16:57
15-year member
UID 179794
Gender Male
Status Offline
I'm quite green, not very familiar with code. But I can see that slore's thinking is relatively rigorous.
Floor 10 Posted 2011-01-16 19:50 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 400
Posts 211
Joined 2007-09-30 18:02
18-year member
UID 98650
Gender Male
Status Offline
Do you all have any new ideas?
Floor 11 Posted 2011-01-18 12:18 ·  中国 上海 东方有线
初级用户
Credits 28
Posts 23
Joined 2010-11-26 11:37
15-year member
UID 178303
Gender Male
Status Offline
Simple, just replace the text. For example, replace "1" with "X" to make it unreadable, and then replace it back when calling.
Floor 12 Posted 2017-08-26 21:48 ·  中国 湖北 武汉 电信
新手上路
Credits 8
Posts 8
Joined 2017-08-21 22:22
8-year member
UID 182480
Gender Male
Status Offline
1、Write the simplest int main(int argc, char * argv[]) program in C. char * argv[] is the first parameter. The program will check the first parameter (which is the password). If successful, return T; if failed, return F.
2、In batch processing, make a SE /P PWD= to require entering the password, and then pass the input value to the program in the first step as the parameter, which is the password, and make a judgment.
3、The batch processing judges whether the input password is correct according to the %errorlevel% return value T/F. If correct, handle the next step; if incorrect, prompt to enter again.
4、In this way, the password is saved in the compiled exe file, generally not visible, unless cracked.
Forum Jump: