Page 1 of 2
how to display password in asterisk
Posted: 14 Jun 2013 03:28
by xhai
hi! can someone help me modify my simple program i want the password display in asterisk for security purpose.. also if possible ecrypt the password..
quickquestion: is this possible to login if my password is encrypt
thank you,
hoping for feedback
@ECHO OFF
TITLE Login Script
COLOR 0a
:USERID
CLS
ECHO Enter User ID:
ECHO > NUL
SET /p USERID=
IF %USERID% EQU xhai GOTO PASSWORD
IF %USERID% LSS xhai GOTO INVALID
IF %USERID% GTR xhai GOTO INVALID
ASSWORD
CLS
ECHO Enter autherization code:
SET /p PASSWORD=
IF %PASSWORD% EQU 123456 GOTO LOADING
IF %PASSWORD% LSS 123456 GOTO INVALID
IF %PASSWORD% GTR 123456 GOTO INVALID
:INVALID
CLS
ECHO INAVLID LOGIN.....
PING -n 3 127.0.0.1 > NUL
ECHO Please try again...
PING -n 3 127.0.0.1 > NUL
GOTO USERID
:LOADING
color 2
echo L
ping localhost -n 2 >nul
cls
echo Lo
ping localhost -n 2 >nul
cls
echo Loa
ping localhost -n 2 >nul
cls
echo Load
ping localhost -n 2 >nul
cls
echo Loadi
ping localhost -n 2 >nul
cls
echo Loadin
ping localhost -n 2 >nul
cls
echo Loading
ping localhost -n 2 >nul
cls
GOTO MAIN
:MAIN
echo Enter 1 PSP USA
echo Enter 2 PSP EUR
echo Enter 3 PSP JAP
echo Enter 4 PSN
echo Enter 5 PSX
echo Enter 6 EXIT
ECHO Enter Choice.
SET /P variable=
IF %variable%==6 EXIT
IF %variable%==5 GOTO PSX
IF %variable%==4 GOTO PSN
IF %variable%==3 GOTO PSP JAP
IF %variable%==2 GOTO PSN EUR
IF %variable%==1 GOTO PSP USA
SP USA
CLS
echo Naruto Akatsuki Rising
echo Naruto Shippuden Ultimate Ninja Heroes 3
echo NBA 2K11
echo Silent Hill Shattered Memories
echo Tekken 6
echo Undead Knights
echo Warrior of Orochi 2
:MAIN
echo Do you want return to Main Menu? (y/n)
set /p start=
if %start% == y CLS goto MAIN
if %start% == n EXIT
goto MAIN
pause
Re: how to display password in asterisk
Posted: 14 Jun 2013 08:14
by Adrianvdh
Hello there
...
Yes it is possible to encrypt and decrypt your password. But your would have to store the information in an another file, such as "temp.bat" and in that file would be...
set "userID=(an encrypted string)"
set "userPass=(an encrypted string)"
than in you main program you would call the bat file...
call "temp.bat"
Ya that is for storing the data
Now for the program I wrote for you in an hour, using supported code
Code: Select all
@echo off &setlocal enabledelayedexpansion
title Batch Login System
color a
mode 40, 10
goto startmenu
reg query "HKU\S-1-5-19" >nul 2>&1 && (
goto startmenu
) || (
echo Run me as Administrator
ping localhost -n 3 >nul
exit )
:startmenu
mode 40, 10
set "userdata=%AppData%\Batch Login System"
if not exist "%userdata%" md "%userdata%"
cls
echo.
echo -- Batch Login System --
echo.
echo 1. Login
echo 2. Sign-up
set /p startmenu=
cls
if "%startmenu%"=="1" goto LogIn
if "%startmenu%"=="2" goto SignUp
goto startmenu
:LogIn
mode 40, 15
echo.
echo -- Batch Login System --
echo -Login-
echo.
echo b/back
echo Enter your username:
set /p loginusername=
if "%loginusername%"=="b" goto startmenu
echo Enter your password:
set /p loginuserpassword=
if "%loginuserpassword%"=="b" (
goto startmenu
) else if exist "%userdata%\%loginusername%".bat (
call "%userdata%\%loginusername%.bat
goto calclogindata
) else (
echo.
echo Username or Password is incorrect...
ping localhost -n 2 >nul
echo Try again...
ping localhost -n 3 >nul
cls
goto LogIn )
:calclogindata
call :DecryptKeys
set Decrypt2=%userpassword%
set "DecryptOut="
:decrypt2
set decrypt_char=%Decrypt2:~0,6%
set Decrypt2=%Decrypt2:~6%
set DecryptOut=%DecryptOut%!CHAR_DE[%decrypt_char%]!
if not "%Decrypt2%"=="" goto decrypt2
if "%loginuserpassword%"=="%DecryptOut%" (
echo.
echo Welcome %loginusername%...
ping localhost -n 2 >nul
echo Redirecting to the main menu...
ping localhost -n 3 >nul
cls
goto mainmenu
) else (
echo.
echo Password is incorrect...
ping localhost -n 2 >nul
echo Try again...
ping localhost -n 3 >nul
cls
goto LogIn )
:SignUp
mode 40, 15
echo.
echo -- Batch Login System --
echo -Sign-Up-
echo.
echo b/back
echo Enter a new username:
set /p signupusername=
if "%signupusername%"=="b" goto startmenu
echo Enter a new password:
set /p signupuserpassword=
if "%signupuserpassword%"=="b" (
goto startmenu
) else (
if exist "%userdata%\%signupusername%".bat (
echo.
echo Username already exists...
ping localhost -n 2 >nul
echo Try again...
ping localhost -n 3 >nul
cls
goto SignUp
) else (
goto savesignupdata ) )
:savesignupdata
call :EncryptKeys
set Encrypt2=%signupuserpassword%
set "EncryptOut="
:encrypt2
set encrypt_char=%Encrypt2:~0,1%
set Encrypt2=%Encrypt2:~1%
set EncryptOut=%EncryptOut%!CHAR_EN[%encrypt_char%]!
if not "%Encrypt2%"=="" goto encrypt2
echo set "userpassword=%EncryptOut%">"%userdata%\%signupusername%".bat
echo.
echo Thank you for signing up!
ping localhost -n 2 >nul
echo Now login to your account...
ping localhost -n 3 >nul
goto LogIn
:EncryptKeys
(set CHAR_EN[a]=UDFM45) & (set CHAR_EN[b]=H21DGF) & (set CHAR_EN[c]=FDH56D) & (set CHAR_EN[d]=FGS546) & (set CHAR_EN[e]=JUK4JH)
(set CHAR_EN[f]=ERG54S) & (set CHAR_EN[g]=T5H4FD) & (set CHAR_EN[h]=RG641G) & (set CHAR_EN[i]=RG4F4D) & (set CHAR_EN[j]=RT56F6)
(set CHAR_EN[k]=VCBC3B) & (set CHAR_EN[l]=F8G9GF) & (set CHAR_EN[m]=FD4CJS) & (set CHAR_EN[n]=G423FG) & (set CHAR_EN[o]=F45GC2)
(set CHAR_EN[p]=TH5DF5) & (set CHAR_EN[q]=CV4F6R) & (set CHAR_EN[r]=XF64TS) & (set CHAR_EN[s]=X78DGT) & (set CHAR_EN[t]=TH74SJ)
(set CHAR_EN[u]=BCX6DF) & (set CHAR_EN[v]=FG65SD) & (set CHAR_EN[w]=4KL45D) & (set CHAR_EN[x]=GFH3F2) & (set CHAR_EN[y]=GH56GF)
(set CHAR_EN[z]=45T1FG) & (set CHAR_EN[1]=D4G23D) & (set CHAR_EN[2]=GB56FG) & (set CHAR_EN[3]=SF45GF) & (set CHAR_EN[4]=P4FF12)
(set CHAR_EN[5]=F6DFG1) & (set CHAR_EN[6]=56FG4G) & (set CHAR_EN[7]=USGFDG) & (set CHAR_EN[8]=FKHFDG) & (set CHAR_EN[9]=IFGJH6)
(set CHAR_EN[0]=87H8G7) & (set CHAR_EN[@]=G25GHF) & (set CHAR_EN[#]=45FGFH) & (set CHAR_EN[$]=75FG45) & (set CHAR_EN[*]=54GDH5)
(set CHAR_EN[(]=45F465) & (set CHAR_EN[.]=HG56FG) & (set CHAR_EN[,]=DF56H4) & (set CHAR_EN[-]=F5JHFH) & (set CHAR_EN[ ]=SGF4HF)
(set CHAR_EN[\]=45GH45) & (set CHAR_EN[/]=56H45G)
exit /b
:DecryptKeys
(set CHAR_DE[UDFM45]=a) & (set CHAR_DE[H21DGF]=b) & (set CHAR_DE[FDH56D]=c) & (set CHAR_DE[FGS546]=d) & (set CHAR_DE[JUK4JH]=e)
(set CHAR_DE[ERG54S]=f) & (set CHAR_DE[T5H4FD]=g) & (set CHAR_DE[RG641G]=h) & (set CHAR_DE[RG4F4D]=i) & (set CHAR_DE[RT56F6]=j)
(set CHAR_DE[VCBC3B]=k) & (set CHAR_DE[F8G9GF]=l) & (set CHAR_DE[FD4CJS]=m) & (set CHAR_DE[G423FG]=n) & (set CHAR_DE[F45GC2]=o)
(set CHAR_DE[TH5DF5]=p) & (set CHAR_DE[CV4F6R]=q) & (set CHAR_DE[XF64TS]=r) & (set CHAR_DE[X78DGT]=s) & (set CHAR_DE[TH74SJ]=t)
(set CHAR_DE[BCX6DF]=u) & (set CHAR_DE[FG65SD]=v) & (set CHAR_DE[4KL45D]=w) & (set CHAR_DE[GFH3F2]=x) & (set CHAR_DE[GH56GF]=y)
(set CHAR_DE[45T1FG]=z) & (set CHAR_DE[D4G23D]=1) & (set CHAR_DE[GB56FG]=2) & (set CHAR_DE[SF45GF]=3) & (set CHAR_DE[P4FF12]=4)
(set CHAR_DE[F6DFG1]=5) & (set CHAR_DE[56FG4G]=6) & (set CHAR_DE[USGFDG]=7) & (set CHAR_DE[FKHFDG]=8) & (set CHAR_DE[IFGJH6]=9)
(set CHAR_DE[87H8G7]=0) & (set CHAR_DE[G25GHF]=@) & (set CHAR_DE[45FGFH]=#) & (set CHAR_DE[75FG45]=$) & (set CHAR_DE[54GDH5]=*)
(set CHAR_DE[45F465]=() & (set CHAR_DE[HG56FG]=.) & (set CHAR_DE[DF56H4]=,) & (set CHAR_DE[F5JHFH]=-) & (set CHAR_DE[SGF4HF]= )
(set CHAR_DE[45GH45]=\) & (set CHAR_DE[56H45G]=/)
exit /b
:mainmenu
mode 40, 12
echo.
echo -- Batch Login System --
echo.
echo -Control Panel-
echo.
echo. 1. Option
echo. 2. Option
echo. 3. Option
set /p mainmenu=
cls
if "%mainmenu%"=="1" goto Option1
if "%mainmenu%"=="2" goto Option2
if "%mainmenu%"=="3" goto Option3
goto mainmenu
:Option1
pause
:Option2
pause
:Option3
pause
Hope it helps you with your log in system
Re: how to display password in asterisk
Posted: 14 Jun 2013 20:21
by Ocalabob
Greetings xhai,
I have this script written by Carlos that I like. There is no encryption but it does mask the input.
Have fun!
Code: Select all
::!CARLOS_HIDE_INPUT.BAT
::Code by Carlos on AMBNT 2013-03-10
::Subject: Getkey without Display the input.
::Thread started by jeb
::Note: My edits/additions are not indented 3 spaces
:::::::::::::BEGIN OF CODE:::::::::::::
@Echo Off
:HInput
::Version 3.0
SetLocal DisableDelayedExpansion
Echo Enter your password below:
Set "Line="
Rem Save 0x08 character in BS variable
For /F %%# In (
'"Prompt;$H&For %%# in (1) Do Rem"'
) Do Set "BS=%%#"
:HILoop
Set "Key="
For /F "delims=" %%# In (
'Xcopy /W "%~f0" "%~f0" 2^>Nul'
) Do If Not Defined Key Set "Key=%%#"
Set "Key=%Key:~-1%"
SetLocal EnableDelayedExpansion
If Not Defined Key Goto :HIEnd
If %BS%==^%Key% (Set /P "=%BS% %BS%" <Nul
Set "Key="
If Defined Line Set "Line=!Line:~0,-1!"
) Else Set /P "=*" <Nul
If Not Defined Line (EndLocal &Set "Line=%Key%"
) Else For /F delims^=^ eol^= %%# In (
"!Line!") Do EndLocal &Set "Line=%%#%Key%"
Goto :HILoop
:HIEnd
Echo(
Echo Your password is '!Line!'
Pause
Goto :Eof
::::::::::::::END OF CODE::::::::::::::
Re: how to display password in asterisk
Posted: 14 Jun 2013 22:06
by Squashman
That should be in the function Library!
Re: how to display password in asterisk
Posted: 15 Jun 2013 05:43
by aGerman
I agree. I like that xcopy method too even if I wonder if there was a better way than letting the batch file copy itself. If xcopy fails for whatever reason you may lose the code. That's potentially dangerous. I fiddled with NUL but wasn't able to persuade xcopy to work properly.
Regards
aGerman
Re: how to display password in asterisk
Posted: 15 Jun 2013 07:40
by foxidrive
This works:
'Xcopy /L /W "%~f0" "%~f0" 2^>Nul'
Re: how to display password in asterisk
Posted: 15 Jun 2013 10:02
by aGerman
Too simple, indeed
Re: how to display password in asterisk
Posted: 15 Jun 2013 15:51
by carlsomo
Great proof of concept. Xcopy will only allow one character input at a time so a user could not copy paste into the password request but that's not a big deal. Functions keys, ESC are ignored. Tab is accepted as are some 'Poison Chars' '~!@#$%^&*()_+-=[]\{}'
Double quotes in the string tend to bomb out but paired double quotes may work only if the string begins and ends with a double quote. Leading spaces are allowed but hard to display with set/p above WinXP. You cannot echo the result if it contains some poison chars like '&' and '|'
Add this line to ignore double quotes:
) Else if ^"==^%Key% (Set "Key="
I modified the routine to put the result in a variable passed as the first argument and accepts an optional Prompt string. If no arg is passed the result is placed in variable "Pa$$word" Returns # of chars in Arg3 and in errorlevel.
All command line arguments are optional
Code: Select all
::!CARLOS_HIDE_INPUT.BAT
::Code by Carlos on AMBNT 2013-03-10
::Subject: Getkey without Display the input.
::Thread started by jeb
::Modified to Return password in Arg1 and length in Arg3 by carlsomo
:::::::::::::BEGIN CODE:::::::::::::
:GetPassword.cmd Password="Prompt" length
@echo off&SetLocal DisableDelayedExpansion
For /F %%# In ('"Prompt;$H&For %%# in (1) Do Rem"') Do Set "BS=%%#"
Set "Line="
<Nul set/p="%~2"
:HILoop
Set "Key="
For /F "delims=" %%# In (
'Xcopy /L /W "%~f0" "%~f0" 2^>Nul'
) Do If Not Defined Key Set "Key=%%#"
Set "Key=%Key:~-1%"
SetLocal EnableDelayedExpansion
If Not Defined Key Goto :HIEnd
If %BS%==^%Key% (
Set /P "=%BS% %BS%" <Nul
Set "Key="
If Defined Line Set "Line=!Line:~0,-1!"&set/a length-=1
) Else if ^"==^%Key% (Set "Key="
) Else set/a length+=1&Set /P "=*" <Nul
If Not Defined Line (
EndLocal& Set "Line=%Key%"& Set/a length=1
) Else For /F delims^=^ eol^= %%# In ("!Line!") Do (
EndLocal& Set "Line=%%#%Key%"& Set "length=%length%"
)
Goto :HILoop
:HIEnd
if not defined Line set/a length=0
EndLocal&EndLocal&(
if not "%~1"=="" (set "%~1=%Line%") Else (set "Pa$$word=%Line%")
if not "%~3"=="" set "%~3=%length%"
)&exit/b %length%
::::::::::::::END OF CODE::::::::::::::
GetPassword.cmd Pwd="Enter your password: " len
<nul set/p="Your password is: '%Pwd%' and is %len% characters in length"
'Ctrl-C' is also accepted as a char by Xcopy without stopping the routine and displays as ')' in the result
Carl
Re: how to display password in asterisk
Posted: 15 Jun 2013 19:29
by aGerman
Find a slightly improved code in this thread: http://www.dostips.com/forum/viewtopic.php?f=3&t=5519&p=33741#p33741. [15 Apr 2014]Good idea to return the string length via errorlevel. You have to use the FOR /F trick to rescue the right value from the sub environment though. BTW you can output poison characters with delayed expansion.
Tried to modify the code to get a function:
Code: Select all
@echo off &setlocal
<nul set /p "=Enter your password: "
call :HInput pw
echo Input length is %errorlevel%
setlocal EnableDelayedExpansion
echo Your password is !pw!
pause
goto :eof
:HInput [ByRef_VarName]
:: inspired by Carlos @ www.DosTips.com
if "%__HI__%" neq "__HI__" (
setlocal DisableDelayedExpansion
set "S=" &set "N=0" &set "__HI__=__HI__"
for /f %%i in ('"prompt;$h&for %%i in (1) do rem"') do set "BS=%%i"
)
set "C="
for /f "delims=" %%i in ('2^>nul xcopy /lw "%~f0" "%~f0"') do if not defined C set "C=%%i"
set "C=%C:~-1%"
setlocal EnableDelayedExpansion
if not defined C (
echo(
if "%~1"=="" (
echo(!S!
endlocal &endlocal &exit /b %N%
) else (
if defined S (
for /f delims^=^ eol^= %%i in ("!S!") do endlocal &endlocal &set "%~1=%%i" &exit /b %N%
) else endlocal &endlocal &set "%~1=" &exit /b 0
)
)
if "!BS!"=="!C!" (
set "C="
if defined S set /a "N -= 1" &set "S=!S:~,-1!" &<nul set /p "=%BS% %BS%"
) else set /a "N += 1" &<nul set /p "=*"
if not defined S (
endlocal &set "N=%N%" &set "S=%C%"
) else for /f delims^=^ eol^= %%i in ("!S!") do endlocal &set "N=%N%" &set "S=%%i%C%"
goto HInput
Regards
aGerman
EDIT: Changed the final assignment.
EDIT2: Bugfix for Enter without input.
Re: how to display password in asterisk
Posted: 15 Jun 2013 22:58
by carlsomo
Here is the output from the modified Carlos routine I submitted running on Win7:
Code: Select all
F:\>getpassword pword="Enter your password: " len
Enter your password: *********************
F:\>echo %errorlevel%
21
F:\>echo %len%
21
F:\>set pword
pword=+_)(*&^%$#@!~?><;'{}\
F:\>set/p="%pword%" <nul
+_)(*&^%$#@!~?><;'{}\
F:\>
It seems to work just fine without double quotes in string since they are ignored in my version.
Your version handles double quotes in string but can you assign it to a command line variable with embedded quotes and spit it our afterward? It would be nice to store it in a variable even with the double quotes. Can you show me how. TIA.
Carl
Re: how to display password in asterisk
Posted: 16 Jun 2013 00:34
by foxidrive
The routine posted by Ocalabob handled doubles quotes just fine. I didn't encounter any character that it couldn't handle, in my tests.
Enter your password below:
*******
Your password is '1"2"asd'
Re: how to display password in asterisk
Posted: 16 Jun 2013 02:54
by xhai
thank you Adrianvdh for your woderfull loginscript
thank yOu calabob for sharing the code
thank you Carlos for your code
thank you carlsomo for your code
@about carlsomo code you added string length just like when you register a new account.. "your password must be in 8 lenght"
Re: how to display password in asterisk
Posted: 16 Jun 2013 13:19
by carlsomo
aGerman:
Thanks for the tips! and sorry to whip a 'Dead Horse' but this could be a very useful routine
Foxdrive:
yes Ocalabob's works fine to display the password but a function version should be called from another routine or the command line and set the variable passed to it with the password characters in it. If quotes are to be allowed then the script has to be able to handle unbalanced double quotes as well as poison characters mixed in with double quotes.
When aGerman's version or my original version with quotes allowed are run with unbalanced quotes or poison characters mixed with quotes they fail:
The string: +_)"(*&^%$" fails
'%$""' is not recognized as an internal or external command,
The string 123"456"789" fails as well with unbalanced quotes
c:>aGerman.bat
Enter your password: ************
*
Input length is 0
Your password is
Press any key to continue . . .
That is why I disabled the quotes. So now I believe the solution is to use the for /f 'trick' in making the final assignment of %~1
I took another stab at it to allow unbalanced double quotes and quotes mixed with poison chars:
Code: Select all
::!CARLOS_HIDE_INPUT.BAT
::Code by Carlos on AMBNT 2013-03-10
::Subject: Getkey without Display the input.
::Thread started by jeb
::Modified to Return password in Arg1 and length in Arg3 by carlsomo
::Allows unbalance quotes and 'poison' characters mixed with quotes
:GetPassword.cmd Password="Prompt" length
@echo off&SetLocal DisableDelayedExpansion
For /F %%# In ('"Prompt;$H&For %%# in (1) Do Rem"') Do Set "BS=%%#"
Set "Line="
<Nul set/p="%~2"
:HILoop
Set "Key="
For /F "delims=" %%# In (
'Xcopy /L /W "%~f0" "%~f0" 2^>Nul'
) Do If Not Defined Key Set "Key=%%#"
Set "Key=%Key:~-1%"
SetLocal EnableDelayedExpansion
If Not Defined Key Goto :HIEnd
rem If ^"==^%Key% Set "Key=0x22"
If %BS%==^%Key% (
Set /P "=%BS% %BS%" <Nul
Set "Key="
If Defined Line set/a length-=1& Set "Line=!Line:~0,-1!"
) Else set/a length+=1&Set /P "=*" <Nul
If Not Defined Line (
EndLocal& Set/a length=1& Set "Line=%Key%"
) Else For /F delims^=^ eol^= %%# In ("!Line!") Do (
EndLocal& Set/a length=%length%& Set "Line=%%#%Key%"
)
Goto :HILoop
:HIEnd
if not defined Line set/a length=0
echo(
if not "%~1"=="" (
For /F delims^=^ eol^= %%# In ("!Line!") Do (
EndLocal&EndLocal&(If not "%~3"=="" Set "%~3=%length%")& Set "%~1=%%#"&exit/b %length
)
) Else (
For /F delims^=^ eol^= %%# In ("!Line!") Do (
EndLocal&EndLocal&(If not "%~3"=="" set "%~3=%length%")& Set "Pa$$word=%%#"&exit/b %length
)
)
)
So with this password: +_)"(*&^%$"abc"123
F:\>getpassword pw="Enter your password: " ln
Enter your password: ******************
F:\>echo Your password is: %pw% with Length: %ln%
Your password is: +_)"(*&^%$"abc"123 with Length: 18
Re: how to display password in asterisk
Posted: 16 Jun 2013 14:01
by aGerman
Indeed that's the key to assign any string. Changed my example above. Thanks Carl.
Re: how to display password in asterisk
Posted: 18 Jun 2013 23:57
by xhai
hi! guys is it possible to combine both batch script.. without messing Adrianvdh script