Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Password In A Bat File  (Read 12984 times)

0 Members and 1 Guest are viewing this topic.

Vbrawl

    Topic Starter


    Newbie

    Thanked: 1
    • Experience: Experienced
    • OS: Windows 10
    Password In A Bat File
    « on: April 07, 2020, 11:50:21 AM »
    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. :)

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Password In A Bat File
    « Reply #1 on: April 07, 2020, 02:32:54 PM »
    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.  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein