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-06-26 22:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] How to modify this code: batch file password verification program View 958 Replies 7
Original Poster Posted 2008-12-12 19:14 ·  中国 重庆 电信
初级用户
★★
Credits 92
Posts 82
Joined 2007-11-13 23:35
18-year member
UID 102602
Gender Male
Status Offline
@echo off 
if not exist bb.txt
for /f "delims=" %%i in (bb.txt) do set passwords=%%i
:begin
cls&set /p password= Please enter the password:
if "%password%"=="%passwords%" goto ok
cls&echo Wrong password&ping /n 2 127.1>nul&goto begin
:set
set select=2
cls&set /p select= Change the password? (default is not to change if you just press Enter): (1. Change 2. Do not change)
if %select% equ 1 goto change
if %select% equ 2 goto ok
if %select% neq 1 if %select% neq 2 goto wrong
:change
set /a n=%random%%%38,m+=1
call,set pwd=%pwd%%%code:~%n%,1%%
if %m% lss 16 goto change
echo :: %pwd%>>%~nx0
cls&echo Please keep your new password safe: %pwd%&pause&goto :eof

:wrong
cls&echo Invalid input, please enter the correct choice!&ping /n 2 127.1>nul&goto set
:ok
cls&echo Correct password!&pause&goto :eof


This code was written by someone else. My idea is:
if the BB.txt file does not exist, then display a prompt (if it exists, then run the password verification program according to bb.txt)
For first-time use, please set a password:
Then save it to BB.txt
When running the program again next time

───────────────── Moderator record ─────────────────
Executed by: HAT
Action: added search keywords to the thread title
Explanation: the original title "Everyone help me see how to modify this code" was not helpful for forum searching
Penalty: deducted 2 credits
Reminder: it is recommended to read the following threads
{1415}The Wisdom of Asking Questions
{7326}Forum newbie must-read, the basic code of conduct for everyone
{22703}Please don't be an impetuous person
{32667} Those people who can't even write a clear title, wake up
{32825}Strict cleanup of lousy posts in this section
───────────────── Moderator record ─────────────────


[ Last edited by HAT on 2008-12-13 at 22:56 ]
Floor 2 Posted 2008-12-12 21:16 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
@echo off
if exist bb.txt goto next
set /p password=For first-time use, please set a password:
echo.%password%>bb.txt

:next

for /f "delims=" %%i in (bb.txt) do set passwords=%%i
:begin
cls&set /p password= Please enter the password:
...


Does the part from :set to :wrong have any chance to execute?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
provem +1 2008-12-13 01:32
Floor 3 Posted 2008-12-13 01:31 ·  中国 重庆 电信
初级用户
★★
Credits 92
Posts 82
Joined 2007-11-13 23:35
18-year member
UID 102602
Gender Male
Status Offline
Can someone write code based on the above idea that can set a password and change a password?
Floor 4 Posted 2008-12-13 01:46 ·  中国 广东 广州 电信
高级用户
★★★
CMD感染者
Credits 691
Posts 383
Joined 2008-05-23 00:38
18-year member
UID 119451
Gender Male
Status Offline
Change:
if "%password%"=="%passwords%" goto ok
to:
if "%password%"=="%passwords%" goto set
Floor 5 Posted 2008-12-13 02:32 ·  中国 重庆 电信
初级用户
★★
Credits 92
Posts 82
Joined 2007-11-13 23:35
18-year member
UID 102602
Gender Male
Status Offline

@echo off

if exist %windir%\bb.txt goto check_pass
set /p password=Please set a password:&echo %password%>%windir%\bb.txt&goto opration_ver
:check_pass
for /f "delims=" %%i in (%windir%\bb.txt) do set passwords=%%i
cls&set /p password=Please enter the password:
if "%password%"=="%passwords%" goto opration_ver
cls&echo Wrong password&ping /n 2 127.1>nul&goto check_pass


Everyone help me take a look, with the code above, after setting the password the content written to bb.txt is: ECHO is off.
Where exactly is the problem?
Floor 6 Posted 2008-12-13 02:35 ·  中国 重庆 电信
初级用户
★★
Credits 92
Posts 82
Joined 2007-11-13 23:35
18-year member
UID 102602
Gender Male
Status Offline

:set_pass
cls&set /p New_pass=Please enter the new password:
cls&set /p New_pass1=Please enter the new password again:
if %New_pass% equ %New_pass1% echo %New_pass%>bb.txt&echo.Set successfully&pause&goto ok
echo.The two passwords entered do not match, please set it again&pause&goto set_pass
:ok
cls&echo Correct password!&pause&goto :eof


This is the code for changing the password. Everyone take a look, is this okay?
Floor 7 Posted 2008-12-13 14:31 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
19-year member
UID 59720
Status Offline
@echo off
if exist M.RQM goto bn
rem llts in 0070303schj by qq251485609
@echo 12345678>M.RQM
:bn
@cls
@echo off
@echo.
@echo.
@echo.
@echo For the security of the user's settings, only the administrator can enter operations in this program!
@echo.
@echo.
@echo Enter T to exit
@echo.
@echo ------- * -------- * --------
@echo.
@echo Initial password: 12345678
@echo.
SET /P SY= Please enter the administrator password:
FOR /F %%I IN (M.RQM) DO SET syq=%%I
IF "%SY%" == "%syq%" GOTO kyjr
IF "%SY%" == "CK" GOTO ckmm
IF "%SY%" == "T" GOTO :eof
@cls
@echo.
@echo.
@echo.
@echo Sorry, (the password may have been changed) you are not an administrator and cannot enter to use the operations!
pause>nul
@goto bn
:kyjr
@cls
@echo.
SET /P SYg= Password correct. Press any key to enter the program (if you need to change the password, please enter XGMM):
IF "%SYg%" == "XGMM" GOTO xg
IF not "%SYg%" == "XGMM" goto k
:xg
@cls
SET /P xmm= Please enter the new password:
@cls
SET /P cxmm= Please enter it once again:

IF "%cxmm%" == "%xmm%" GOTO gng
@echo Passwords do not match!
pause
goto xg
:gng
@echo %xmm%>M.RQM
@echo Password changed successfully! Please remember this password %xmm%
pause>nul
goto bn
:ckmm
@cls
FOR /F %%I IN (M.RQM) DO SET syq=%%I
@echo %syq%
pause>nul
goto bn
:k
@cls
@echo Entering the program
pause>nul


[ Last edited by ZJHJ on 2008-12-13 at 21:31 ]
Floor 8 Posted 2008-12-13 21:53 ·  中国 重庆 电信
初级用户
★★
Credits 92
Posts 82
Joined 2007-11-13 23:35
18-year member
UID 102602
Gender Male
Status Offline
Thanks, ZJHJ.
What I wanted was: if the M.rqm file does not exist, then prompt the user to set a password; if it exists, then use the contents of M.Rqm to verify the password. I've already solved the problem, thanks.
Forum Jump: