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

Author Topic: open with password  (Read 3401 times)

0 Members and 1 Guest are viewing this topic.

abubibo

    Topic Starter


    Rookie

    open with password
    « on: February 24, 2010, 03:21:42 AM »
    Hi friends
    I need to create a batch file that promts user to enter a password, if the password is correct (to be defined in the code) a certain welcoming string will be displayed and a certain executable file will run (install.exe). If password is not correct a regreting string will be displayed and the batch file closed.
    Can you help?

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: open with password
    « Reply #1 on: February 24, 2010, 03:37:47 AM »
    Welcome to Computer Hope. This question has been covered many times, but in case you missed it, this little snippet will work:

    Code: [Select]
    @echo off
    echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>hide.com

    :retry
    set /p userid=Enter UserId:
    set /p password=Enter password: <nul
    for /f "tokens=*" %%i in ('hide.com') do set password=%%i
    if /i %password%==password goto next
    cls
    echo Try again. You are not logged in!
    goto retry

    :next
    echo. & echo You are logged in!
    del hide.com

    Having the password in plain site is a security breach. It is probably better to hide the password in an encrypted database or even the registry. A better approach would be VBScript or Powershell.

    Good luck.  8)

    The correct password to the file is password.
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    abubibo

      Topic Starter


      Rookie

      Re: open with password
      « Reply #2 on: February 24, 2010, 03:55:22 AM »
      Grateful to your kind reply
      I copied the code into a notepad file but when I run it, it promts me to enter userID and closes whatever I enter
      Have I made any mistake?

      thanks again

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: open with password
      « Reply #3 on: February 24, 2010, 04:22:12 AM »
      Quote
      Have I made any mistake?

      Possibly. Check your bat file against the original posted code. I cannot duplicate your error. The userID is not checked, so anything you enter is acceptable.

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      tommyroyall



        Rookie

        Thanked: 1
        Re: open with password
        « Reply #4 on: February 24, 2010, 05:02:30 PM »
        Or you could use this example:
        Code: [Select]
        @echo off
        :MAIN
        set password=yourdesiredpassword
        echo Enter the password.
        set /p input=Password:
        if %input%==%password% goto WHATEVER_COMES_NEXT

        greg



          Intermediate

          Thanked: 7
          Re: open with password
          « Reply #5 on: February 24, 2010, 06:51:17 PM »
          "I need to create a batch file that promts user to enter a password, if the password is correct (to be defined in the code) a certain welcoming string will be displayed"


          C:\>type  tom.bat
          Code: [Select]
          @echo off
          :begin
          set password=hello
          echo password = %password%
          echo Enter the password.
          set /p input=
          echo input = %input%
          if %input%==%password% goto NEXT
          echo Wrong password
          echo try again
          goto  begin
          :NEXT
          echo I'm in next
          echo password is correct
          echo  proceed

          Output:

          C:\>tom.bat
          password = hello
          Enter the password.
          joe22
          input = joe22
          Wrong password
          try again
          password = hello
          Enter the password.
          what
          input = what
          Wrong password
          try again
          password = hello
          Enter the password.
          hello
          input = hello
          I'm in next
          password is correct
           proceed

          C:\>
          Have a Nice Day