Page 1 of 1
batch login system help :)
Posted: 10 Jan 2011 07:24
by trap
Hello guys! First time posting..
I have a batch scripts who lets the user register and then ask's him to log in with the user he created.
All i want is that when he registeres his password, the input should be blank or "**'s".
I will post my code:
Code: Select all
@echo off
title Login System
color a
cls
echo Please register
echo.
set /p user=Username:
set /p pass=Password:
cls
echo Your account %user% has been created.
echo.
pause
cls
:A
echo Please Login.
echo.
set /p u=Username:
set /p p=Password:
if %u%==%user% if %p%==%pass% goto B
cls
echo Invalid Username or Password
echo.
pause
cls
goto A
:B
echo You are now logged in as %user%.
echo.
pause
cls
exit
Im really glad for any help
-Trap
Re: batch login system help :)
Posted: 10 Jan 2011 17:22
by aGerman
Hmm,
bad news 1: A login in batch is absolutely senseless.
bad news 2: There is no chance to replace characters of an user input with asterisks using native batch.
If you're working on a 32 Bit Windows OS it is possible to create and execute a 16 Bit COM application by batch. This could be helpfull in this case.
Have a look at this complicated and buggy function, then decide for yourself if you would like to use it (or better not
)
Code: Select all
@echo off &setlocal
:: Call :GetPassInput function with
:: the text to display (first argument),
:: the wildcard character you would like to display (second argument)
:: and the variable name for output (third argument).
call :GetPassInput "Enter your password:" "*" pass
:: Do what ever you want with variable %pass%
echo\%pass%
pause
goto :eof
:::::::::::::::: Function to get the password input ::::::::::::::::::::::::::::
:GetPassInput Text WildCard VariableName
setlocal EnableDelayedExpansion
set "inp="
set "out="
set "spaces="
set "asterisks="
pushd "%temp%"
(
echo\a 100
echo\mov ah,00
echo\int 16
echo\mov ah,4c
echo\int 21
echo\
echo\rcx
echo\108
echo\n GETCH16.COM
echo\w
echo\q
echo\
)>GETCH16.ASM
start "" /wait /min cmd /k "(type GETCH16.ASM|debug)&exit"
del GETCH16.ASM
set "X=."
for /L %%c in (1,1,13) DO set X=!X:~0,4094!!X:~0,4094!
echo !X! > "cr.tmp"
echo\>> "cr.tmp"
for /f "tokens=2 usebackq" %%a in ("cr.tmp") do set cr=%%a
del "cr.tmp"
popd
for /f "delims=:" %%i in (
'^(echo\"%~1"^&echo\^)^|findstr /o $'
) do set /a len=%%i-2
for /l %%i in (1,1,%len%) do set "spaces=!spaces! "
<nul set /p ".=.!cr!%spaces%!cr!"
<nul set /p ".=!cr!%~1 %asterisks%"
:___inputLoop
call "%temp%\getch16.com"
if %errorlevel% gtr 126 goto ___inputLoop
if %errorlevel% lss 32 (
if %errorlevel%==8 (
if "%asterisks%" neq "" (
set "spaces=%spaces:~1%"
set "asterisks=%asterisks:~1%"
for /f "tokens=1*" %%a in ("%inp%") do set "inp=%%b"
)
<nul set /p ".=.!cr!!spaces!!cr!"
<nul set /p ".=!cr!%~1 !asterisks!"
goto ___inputLoop
)
if %errorlevel%==13 goto ___ahead
)
set "inp=%errorlevel% %inp%"
set "asterisks=%asterisks%%~2"
set "spaces=%spaces% "
<nul set /p ".=.!cr!%spaces%!cr!"
<nul set /p ".=!cr!%~1 %asterisks%"
goto :___inputLoop
:___ahead
echo\
del "%temp%\getch16.com"
for %%a in (%inp%) do (
cmd /c exit %%a
set "out=!=ExitCodeAscii!!out!"
)
endlocal &set "%~3=%out%"
goto :eof
Regards
aGerman
Re: batch login that shows "*"'s
Posted: 28 Feb 2011 21:41
by InterociterOperator
If you have the CHOICE.com program on your machine, here is one bit of trickery to get *'s that we used.
It isn't very secure really - more for fun than anything else.
Copy it to notepad and give it a run.
A bit long, but it doesn't echo your entire password to the screen.
A-Z (except "x") and 0-9 are allowable password characters.
The password is "GOODPLANE262".
Code: Select all
rem =========================================================================
rem PASSWORD.BAT - InterociterOperator 2011
@echo off
color 70
mode 60,31
prompt W:\SECURITY$g
:BEGIN
set pw=
set dots=
set width=
set screen=
if "x" == "x" call :setwidth
:show
cls
if "%screen%" == "%width%" goto allowin
echo - vers 0.125
echo -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
echo "
echo "
echo "
echo "
echo "
echo " I N T E R O C I T E R
echo "
echo "
echo " M A I N T E N A N C E S C R E E N
echo "
echo "
echo "
echo "
echo " Enter your password here.
echo " -------------------------
echo " -> %dots%
echo " -------------------------
echo "
echo "
echo "
:cont
echo "
echo "
echo "
echo "
echo " (Press [X] if you need to restart)
echo "
rem the following two lines are one line wrapped
choice /n /t:-,99 /c:ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- "-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
if errorlevel==37 goto s-37
if errorlevel==36 goto s-36
if errorlevel==35 goto s-35
if errorlevel==34 goto s-34
if errorlevel==33 goto s-33
if errorlevel==32 goto s-32
if errorlevel==31 goto s-31
if errorlevel==30 goto s-30
if errorlevel==29 goto s-29
if errorlevel==28 goto s-28
if errorlevel==27 goto s-27
if errorlevel==26 goto s-26
if errorlevel==25 goto s-25
if errorlevel==24 goto s-24
if errorlevel==23 goto s-23
if errorlevel==22 goto s-22
if errorlevel==21 goto s-21
if errorlevel==20 goto s-20
if errorlevel==19 goto s-19
if errorlevel==18 goto s-18
if errorlevel==17 goto s-17
if errorlevel==16 goto s-16
if errorlevel==15 goto s-15
if errorlevel==14 goto s-14
if errorlevel==13 goto s-13
if errorlevel==12 goto s-12
if errorlevel==11 goto s-11
if errorlevel==10 goto s-10
if errorlevel==9 goto s-9
if errorlevel==8 goto s-8
if errorlevel==7 goto s-7
if errorlevel==6 goto s-6
if errorlevel==5 goto s-5
if errorlevel==4 goto s-4
if errorlevel==3 goto s-3
if errorlevel==2 goto s-2
if errorlevel==1 goto s-1
::
:: - - - - - - - -
::
:s-37
set pw=QUARZIBARM
set screen=80
exit
::
goto show
:s-36
set screen=%screen%0
set dots=%dots%*
goto show
:s-35
set screen=%screen%9
set dots=%dots%*
goto show
:s-34
set screen=%screen%8
set dots=%dots%*
goto show
:s-33
set screen=%screen%7
set dots=%dots%*
goto show
:s-32
set screen=%screen%6
set dots=%dots%*
goto show
:s-31
set screen=%screen%5
set dots=%dots%*
goto show
:s-30
set screen=%screen%4
set dots=%dots%*
goto show
::
:s-29
set screen=%screen%3
set dots=%dots%*
goto show
::
:s-28
set screen=%screen%2
set dots=%dots%*
goto show
::
:s-27
set screen=%screen%1
set dots=%dots%*
goto show
::
:s-26
set screen=%screen%Z
set dots=%dots%*
goto show
::
:s-25
set screen=%screen%Y
set dots=%dots%*
goto show
::
:s-24
::set screen=%screen%X
::set dots=%dots%*
goto begin
::
:s-23
set screen=%screen%W
set dots=%dots%*
goto show
::
:s-22
set screen=%screen%V
set dots=%dots%*
goto show
::
:s-21
set screen=%screen%U
set dots=%dots%*
goto show
::
:s-20
set screen=%screen%T
set dots=%dots%*
goto show
::
:s-19
set screen=%screen%S
set dots=%dots%*
goto show
::
:s-18
set screen=%screen%R
set dots=%dots%*
goto show
::
:s-17
set screen=%screen%Q
set dots=%dots%*
goto show
::
:s-16
set screen=%screen%P
set dots=%dots%*
goto show
::
:s-15
set screen=%screen%O
set dots=%dots%*
goto show
::
:s-14
set screen=%screen%N
set dots=%dots%*
goto show
::
:s-13
set screen=%screen%M
set dots=%dots%*
goto show
::
:s-12
set screen=%screen%L
set dots=%dots%*
goto show
::
:s-11
set screen=%screen%K
set dots=%dots%*
goto show
::
:s-10
set screen=%screen%J
set dots=%dots%*
goto show
::
:s-9
set screen=%screen%I
set dots=%dots%*
goto show
::
:s-8
set screen=%screen%H
set dots=%dots%*
goto show
::
:s-7
set screen=%screen%G
set dots=%dots%*
goto show
::
:s-6
set screen=%screen%F
set dots=%dots%*
goto show
::
:s-5
set screen=%screen%E
set dots=%dots%*
goto show
::
:s-4
set screen=%screen%D
set dots=%dots%*
goto show
::
:s-3
set screen=%screen%C
set dots=%dots%*
goto show
::
:s-2
set screen=%screen%B
set dots=%dots%*
goto show
::
:s-1
set screen=%screen%A
set dots=%dots%*
goto show
::
goto show
:allowin
cls
prompt $p$g
set pw=FOOGLE
set screen=80
set width=80
color 0F
echo ==========================================================
echo = =
echo = =
echo = =
echo = A C C E S S G R A N T E D ! ! ! =
echo = =
echo = =
echo = =
echo = fire phasers sound trumpet =
echo ==========================================================
choice /n /c:YN- /t:-,3
cls
color 9f
echo "Use BAT2EXE to hide file contents."
echo "Don't grant FileScan rights."
echo "Run from second program."
echo "Map excessively obscure path here."
echo "Did you remember to include the CHOICE.com program in your path?"
echo "Point to Menu here."
choice /n /c:YN- /t:-,3
goto :eof
:setwidth
rem InterociterOperator 2011
set width=GOODPLANE262
goto :eof
rem ========================================================================
[EDIT aGerman]@phillid: Code tags complemented. [/EDIT]
Re: batch login system help :)
Posted: 28 Feb 2011 21:45
by InterociterOperator
In the editor, the following line wraps. Disregard the remark above about it wrapping
choice /n /t:-,99 /c:ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- "-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
looks like...
choice /n /t:-,99 /c:ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-
"-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
...in the editor.. sorry.
Re: batch login system help :)
Posted: 04 Mar 2011 17:16
by phillid
That's pretty neat, I've written a few password protection batch scripts and compiled them into .EXEs
PS: Please post code inside code tags next time
Re: batch login system help :)
Posted: 08 Mar 2011 12:46
by InterociterOperator
What is the best way to get the length of a variable for later manipulation?
Re: batch login system help :)
Posted: 08 Mar 2011 13:07
by aGerman
Re: batch login system help :)
Posted: 27 Sep 2011 03:29
by trap
Thanks for all the reply's
Re: batch login system help :)
Posted: 07 Oct 2011 00:15
by Rileyh
InterociterOperator,
Your code has many errors.
Unfortunately for my low-level abilities with batch code I cannot propose alternatives but when I copied your code into a batch file and tested it it just exploded with code and shut down.
I cannot see what you were trying to do with it but could you place a reply.
Thanks,
Rileyh
Re: batch login system help :)
Posted: 07 Oct 2011 00:18
by Rileyh
aGerman,
Your code did not work at all. (no offence as you are probably 1000 times more accomplished than me)
All it did was freeze and do nothing.
By the way, why did you use assembly in the code?
Rileyh
Re: batch login system help :)
Posted: 24 May 2012 19:09
by InterociterOperator
You have to have the "Choice" command available from the command prompt for the code to work.
Re: batch login system help :)
Posted: 25 May 2012 05:26
by Squashman
InterociterOperator wrote:You have to have the "Choice" command available from the command prompt for the code to work.
I guess 7 months is better late than never.
Re: batch login system help :)
Posted: 26 May 2012 02:47
by Jronicaing
Your code did not work at all. (no offence as you are probably 1000 times more accomplished than me)
All it did was freeze and do nothing.