1.

Solve : Password In A Bat File?

Answer»

Hello, i need help with the code:

@ECHO OFF
set tries=3
set password=PaSsWoRd
:checker
if %tries% EQU "0" goto :EXIT
Echo You have %tries% attempts!
color 5
set /P pass= Enter Password:
if /I %pass% EQU %password% (echo Secret_Message| clip
) else (set /a tries=%tries% -1 goto :checker)
EXIT
exit
_______________________________________ __________________________________
When i WRITE a wrong password i get a "Missing operator." ERROR. But when i write the right password it works.
I want the program to ask for a password then check it and if it's the right password then change the clipboard, if the password is wrong the 1st time go BACK and put the password again,the 2nd time the same and the 3rd to close.

Thanks in advance. The missing operand is an ampersand.

Code: [Select]) else (set /a tries=%tries% -1 & goto :checker)

There is also no exit after 3 attempts. When I tested your code, I was informed I had -6 attempts.
FYI: using the /i switch on the if is case insensitive. This would make PaSsWoRd and password equal; your choice

This may help:
Code: [Select]@echo off
setlocal enabledelayedexpansion
set pswd=PaSsWoRd

for /l %%i in (3, -1, 1) do (
echo You Have %%i Attempts LEFT
set /p pass=Enter Password:
if /i !pswd!==!pass! (echo Secret Message | clip) & goto continue
if %%i==1 echo Failed Security Check & exit /B
)
:continue

Good luck.



Discussion

No Comment Found