hide entered password with astrics

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

hide entered password with astrics

#1 Post by abc0502 » 23 Apr 2012 16:36

Is it possible to hide the password that being entered in that code and replace it with astrics or any symbole
so the password won't become visible when entering it
here is a sample code:

Code: Select all

@echo off
cls
loop
Echo Test Code
set /p "cho1=>"
if %errorlevel%==1 goto loop
if %cho1%==1234 ( echo Access guaranteed
) Else ( echo Access Denied )
pause >nul

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: hide entered password with astrics

#2 Post by aGerman » 23 Apr 2012 16:55

I remember former discussions about that theme.
Nobody implemented masked password input to batch code because it's senseless. Batch code is plain text. Everybody can read it, everybody can change it.

Regards
aGerman

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: hide entered password with astrics

#3 Post by foxidrive » 23 Apr 2012 17:01

Herbert Kleebauer wrote this - the password is invisible IE no asterisks or other indication.

Code: Select all

@echo off
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x>in.com
set  /p password=Enter password:<nul
for /f "tokens=*" %%i in ('in.com') do set password=%%i
del in.com
echo.
echo The Password is:"%password%"



However if you are comparing it with text in a batch file then there isn't much security anyway.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: hide entered password with astrics

#4 Post by abc0502 » 23 Apr 2012 17:26

Thanks aGerman and Foxidrive for your help,
i'm going to change the batch to exe using bat2exe converter found here: http://www.f2ko.de/programs.php?lang=en so the password will remain hidden.

And foxidrive the code u posted work fine with me all what i need is to hide the password while entering it
thanks :D
note i can't nullfy the variable like u said before or use error level with it but it will do the job :)

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: hide entered password with astrics

#5 Post by Squashman » 24 Apr 2012 05:42

abc0502 wrote:Thanks aGerman and Foxidrive for your help,
i'm going to change the batch to exe using bat2exe converter found here: http://www.f2ko.de/programs.php?lang=en so the password will remain hidden.

And foxidrive the code u posted work fine with me all what i need is to hide the password while entering it
thanks :D
note i can't nullfy the variable like u said before or use error level with it but it will do the job :)

That is only pseudo hiding it. When you execute the packaged EXE all it does is extract the batch file to the current directory or to a temp directory. If there is any stops for input into your batch file all they have to do is find the batch file that was extracted and open it up view all the code and the password.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: hide entered password with astrics

#6 Post by abc0502 » 24 Apr 2012 16:23

hi Squashman,
I know it is easy for some one who know how batch files work to extract the password from the batch file, but for some one dosn't have any idea what is batch it won't be easy beside how he will know what language the exe file is written in and i hide the password using many variable in many places in the batch so it will be hard to find for a someone dosn't know batch files.

i'm trying to find some sort of encryption using batch but i found something using another program in the webside up hope it work :)

Cat
Posts: 32
Joined: 11 Nov 2011 12:04

Re: hide entered password with astrics

#7 Post by Cat » 24 Apr 2012 16:27

Best I could do with pure batch:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set chars=q w e r t y u i o p a s d f g h j k l z x c v b n m 1 2 3 4 5 6 7 8 9 0
:input
cls
echo input password:
if defined display echo %display%
choice /c "!chars: =!" >nul
if not %errorlevel%==37 (
   for /f "tokens=%errorlevel%" %%a in ("%chars%") do set input=%%a
   set password=%password%%input%
   set display=%display%*
   goto input
) else (
   echo your password is: %password%
   pause
)
exit

Doesn't work all the way. Did you consider using a C++ executable to go with your batch file?

phillid
Posts: 109
Joined: 03 Apr 2010 20:27
Location: Wellington, New Zealand
Contact:

Re: hide entered password with astrics

#8 Post by phillid » 25 Apr 2012 03:20

C/C++ - This is where I come in :P :)
Does anyone want a program (an exe) to take input for batch scripts without showing the text that's being typed in? :)

Thanks,
Phillid

Cat
Posts: 32
Joined: 11 Nov 2011 12:04

Re: hide entered password with astrics

#9 Post by Cat » 26 Apr 2012 14:44

@ Phillid - I have this in C++ right now, but how do I set a variable (%password%, etc) from the script?

Code: Select all

#include "stdafx.h"
#include <string>
#include <conio.h>
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
int main(char argc, char *argv[]) {
   char c;
   string password;
   if (argv[1] != 0) {
           printf(argv[1]);
       }
   }
    do {
        c = _getch();
      switch(c)    {case 0: {
      _getch();
                break;
                }
            case '\b': {
                if(password.size() != 0) {
                    printf("\b \b");
                    password.erase(password.size() - 1, 1);
            }
                break;       
            }   
            default: {
                if(isalnum(c) || ispunct(c)) {
               password += c;
                    printf("*");
                }
                break;
            }
        }
    } while(c != '\r');
   cout << " " + password;
}

MrKnowItAllxx
Posts: 43
Joined: 20 Mar 2012 20:53

Re: hide entered password with astrics

#10 Post by MrKnowItAllxx » 26 Apr 2012 17:56

Cat, you could do this in the batch file: (I think)

Code: Select all

for /f %%a in ('password.exe') do set "password=%%a"


but you would need to only output the password with the exe, you currently output a space before the password aswell

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: hide entered password with astrics

#11 Post by aGerman » 27 Apr 2012 04:24

@Cat

C/C++ is a bit off topic in a Batch forum. It's a Batch tool though for that reason a small hint:
Use different streams - write the asterisks to stdErr (std::cerr) and the password to stdOut (std::cout). The FOR /F loop in the Batch code does only handle the stdOut stream while the stdErr stream will be displayed directly.

Regards
aGerman

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: hide entered password with astrics

#12 Post by Squashman » 27 Apr 2012 05:36


Post Reply