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

Author Topic: hide prompt input (when asked for password)  (Read 4636 times)

0 Members and 1 Guest are viewing this topic.

yperron

    Topic Starter


    Rookie
    hide prompt input (when asked for password)
    « on: October 30, 2007, 01:51:29 PM »
    Hi,

    I have a batch file that needs to ask the user a password if I do:

    > set /p IN_PASSWORD=enter your password:
    enter your password:  PSWD

    but I would like the command window to hide the letters with * as the user types it, like
    enter your password: ****

    is there a tool that would allow to overwrite a letter at a certain position?
    is there a way to get input character by character?

    thanks
    yp
    yp

    yperron

      Topic Starter


      Rookie
      Re: hide prompt input (when asked for password)
      « Reply #1 on: October 30, 2007, 03:34:06 PM »
      for now I have something but I have to do a enter after each character in order to get it work, it looks like this:

      Code: [Select]
      :SET_PASSWD
      set IN_PAWD=
      set TEMP_PAWD=
      set COUNT=0

      :SET_PASSWD2
      SET HIDEN_PAWD=
      cls
      FOR /L %%I IN (1,1,%COUNT%) DO call SET HIDEN_PAWD=!HIDEN_PAWD!*
      set /p TEMP_PAWD=enter your password: %HIDEN_PAWD%
      SET IN_PAWD=%IN_PAWD%%TEMP_PAWD%
      set /a COUNT=%COUNT%+1
      goto :SET_PASSWD2

      so basically if I comment the cls command it gives me the output:
      Code: [Select]
      enter your password:  a
      enter your password:  *b
      enter your password:  **c
      enter your password:  ***d
      enter your password:  ****e
      enter your password:  *****f
      enter your password:  ******

      So basically what I need now is to find a way to gather character one by one (without having to do enter) and then exits from my loop when the character entered is a actually an enter... :-\

      thanks ;D
      yp
      yp

      yperron

        Topic Starter


        Rookie
        Re: hide prompt input (when asked for password)
        « Reply #2 on: October 31, 2007, 02:10:06 PM »
        Since I got no answer  :'(
        I give up and used the simple trick to change text color to be the same one as the background:

        Code: [Select]
          ECHO enter your password:
          SFK COLOR black
          SET /p IN_PAWD=
          SFK COLOR grey

        the only thing is that if you copy/paste the content of the screen you will see it ::)
        and when you scolled up the command typed, you will see it either!

        it fills my needs for now since it was not for nationnal security passwords ;)
        yp
        yp

        Carbon Dudeoxide

        • Global Moderator

        • Mastermind
        • Thanked: 169
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Experience: Guru
        • OS: Mac OS
        Re: hide prompt input (when asked for password)
        « Reply #3 on: November 01, 2007, 06:58:19 AM »
        This may be what you're looking for.
        I got this online, didn't make it myself.
        @echo off
        SET REAL_PASS=pass
        SET REAL_LENGTH=****

        echo e100 B4 00 CD 16 88 E0 B4 4C CD 21> %temp%.\\\\scan.com
        for %%? in (rcx A w q) do echo %%?>> %temp%.\\\\scan.com
        type %temp%.\\\\scan.com |DEBUG %temp%.\\\\scan.com > nul

        :pre
        for %%? in (pass length) do set user_%%?=

        :loop
        set input=
        cls
        echo Type password: %user_length%
        if \\"%user_pass%\\"==\\"%real_pass%\\" goto granted
        if \\"%user_length%\\"==\\"%real_length%\\" goto denied
        call %temp%.\\\\scan.com
        if errorlevel=2 if not errorlevel=3 set input=1
        if errorlevel=3 if not errorlevel=4 set input=2
        if errorlevel=4 if not errorlevel=5 set input=3
        if errorlevel=5 if not errorlevel=6 set input=4
        if errorlevel=6 if not errorlevel=7 set input=5
        if errorlevel=7 if not errorlevel=8 set input=6
        if errorlevel=8 if not errorlevel=9 set input=7
        if errorlevel=9 if not errorlevel=10 set input=8
        if errorlevel=10 if not errorlevel=11 set input=9
        if errorlevel=11 if not errorlevel=12 set input=0
        if errorlevel=30 if not errorlevel=31 set input=a
        if errorlevel=48 if not errorlevel=49 set input=b
        if errorlevel=46 if not errorlevel=47 set input=c
        if errorlevel=32 if not errorlevel=33 set input=d
        if errorlevel=18 if not errorlevel=19 set input=e
        if errorlevel=33 if not errorlevel=34 set input=f
        if errorlevel=34 if not errorlevel=35 set input=g
        if errorlevel=35 if not errorlevel=36 set input=h
        if errorlevel=23 if not errorlevel=24 set input=i
        if errorlevel=36 if not errorlevel=37 set input=j
        if errorlevel=37 if not errorlevel=38 set input=k
        if errorlevel=38 if not errorlevel=39 set input=l
        if errorlevel=50 if not errorlevel=51 set input=m
        if errorlevel=49 if not errorlevel=50 set input=n
        if errorlevel=24 if not errorlevel=25 set input=o
        if errorlevel=25 if not errorlevel=26 set input=p
        if errorlevel=16 if not errorlevel=17 set input=q
        if errorlevel=19 if not errorlevel=20 set input=r
        if errorlevel=31 if not errorlevel=32 set input=s
        if errorlevel=20 if not errorlevel=21 set input=t
        if errorlevel=22 if not errorlevel=23 set input=u
        if errorlevel=47 if not errorlevel=48 set input=v
        if errorlevel=17 if not errorlevel=18 set input=w
        if errorlevel=45 if not errorlevel=46 set input=x
        if errorlevel=21 if not errorlevel=22 set input=y
        if errorlevel=44 if not errorlevel=45 set input=z
        if errorlevel=71 if not errorlevel=72 set input=7
        if errorlevel=72 if not errorlevel=73 set input=8
        if errorlevel=73 if not errorlevel=74 set input=9
        if errorlevel=75 if not errorlevel=76 set input=4
        if errorlevel=76 if not errorlevel=77 set input=5
        if errorlevel=77 if not errorlevel=78 set input=6
        if errorlevel=79 if not errorlevel=80 set input=1
        if errorlevel=80 if not errorlevel=81 set input=2
        if errorlevel=81 if not errorlevel=82 set input=3
        if errorlevel=82 if not errorlevel=83 set input=0
        if \\"%input%\\"==\\"\\" goto loop
        set user_length=*%user_length%
        set user_pass=%user_pass%%input%
        goto loop

        :granted
        cls
        echo Access granted.
        goto pass_end

        :denied
        del %temp%.\\\\scan.com
        cls
        echo.
        echo Access Denied.
        echo.
        echo.
        pause
        exit

        :pass_end
        cls
        for %%? in (pass length) do set user_%%?=
        for %%? in (pass length) do set real_%%?=
        del %temp%.\\\\scan.com
        echo.
        echo. Acsess Granted.
        echo.
        echo.
        pause
        exit

        yperron

          Topic Starter


          Rookie
          Re: hide prompt input (when asked for password)
          « Reply #4 on: November 01, 2007, 08:37:47 AM »
          Thanks Carbon! :)

          This is exactly the kind of answer I was looking for!

          but I looked at it and tried it but I cannot understand :-[ what does the program created at the beginning:

          Code: [Select]
          >type %temp%.\\\\scan.com
          e100 B4 00 CD 16 88 E0 B4 4C CD 21
          rcx
          A
          w
          q

          I bet this is what it uses to gather character one by one since it is called just before checking the input...

          at least I have a working example, thanks again!  :D
          yp
          yp