DosTips.com

A Forum all about DOS Batch
It is currently 19 Aug 2017 22:05

All times are UTC-06:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: 23 Apr 2012 16:36 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
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


Top
   
PostPosted: 23 Apr 2012 16:55 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2758
Location: Germany
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


Top
   
PostPosted: 23 Apr 2012 17:01 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 6033
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.


Top
   
PostPosted: 23 Apr 2012 17:26 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
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 :)


Top
   
PostPosted: 24 Apr 2012 05:42 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3509
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.


Top
   
PostPosted: 24 Apr 2012 16:23 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
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 :)


Top
   
PostPosted: 24 Apr 2012 16:27 
Offline

Joined: 11 Nov 2011 12:04
Posts: 32
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?


Top
   
PostPosted: 25 Apr 2012 03:20 
Offline

Joined: 03 Apr 2010 20:27
Posts: 109
Location: Wellington, New Zealand
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


Top
   
PostPosted: 26 Apr 2012 14:44 
Offline

Joined: 11 Nov 2011 12:04
Posts: 32
@ 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;
}


Top
   
PostPosted: 26 Apr 2012 17:56 
Offline

Joined: 20 Mar 2012 20:53
Posts: 43
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


Top
   
PostPosted: 27 Apr 2012 04:24 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2758
Location: Germany
@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


Top
   
PostPosted: 27 Apr 2012 05:36 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3509
How about something like this.
http://www.ericphelps.com/batch/samples ... rd.bat.txt


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited