Page 1 of 1

hide entered password with astrics

Posted: 23 Apr 2012 16:36
by abc0502
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

Re: hide entered password with astrics

Posted: 23 Apr 2012 16:55
by aGerman
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

Re: hide entered password with astrics

Posted: 23 Apr 2012 17:01
by foxidrive
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.

Re: hide entered password with astrics

Posted: 23 Apr 2012 17:26
by abc0502
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 :)

Re: hide entered password with astrics

Posted: 24 Apr 2012 05:42
by Squashman
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.

Re: hide entered password with astrics

Posted: 24 Apr 2012 16:23
by abc0502
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 :)

Re: hide entered password with astrics

Posted: 24 Apr 2012 16:27
by Cat
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?

Re: hide entered password with astrics

Posted: 25 Apr 2012 03:20
by phillid
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

Re: hide entered password with astrics

Posted: 26 Apr 2012 14:44
by Cat
@ 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;
}

Re: hide entered password with astrics

Posted: 26 Apr 2012 17:56
by MrKnowItAllxx
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

Re: hide entered password with astrics

Posted: 27 Apr 2012 04:24
by aGerman
@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

Re: hide entered password with astrics

Posted: 27 Apr 2012 05:36
by Squashman