7036
Goto Top

Suche Batch mit unsichtbarer Kennworteingabe

Hi suche eine Möglichkeit in der Windowsshell die Kennwort-Eingabe des Anwenders einzulesen.

zur Zeit mache ich das mit:

@set /p "psw=%USERNAME% geben Sie bitte ihr Kennwort ein: "
Aber dabei wird die Eingabe im Klartext eingegeben...
kennt jemand eine andere Möglichkeit?

Danke

Content-Key: 39068

Url: https://administrator.de/contentid/39068

Printed on: April 24, 2024 at 06:04 o'clock

Member: geTuemII
geTuemII Aug 30, 2006, updated at Oct 18, 2012 at 15:57:10 (UTC)
Goto Top
Hallo Siggi,

das hatten wir schon einmal. Es geht im Batch offenbar nicht so ohne weiteres:

Passwort eingeben aber ****** anzeigen

HTH geTuemII
Mitglied: 7036
7036 Aug 30, 2006 at 19:03:22 (UTC)
Goto Top
Ja hatte ich auch gefunden,

aber ich dachte da an etwas wie eine Eingabe per < einlesen.
Möchte nur keine Eingabe anzeigen lassen...

Danke
Member: maneich
maneich Aug 31, 2006 at 00:29:33 (UTC)
Goto Top
Hallo,

versuche es mal damit:

pw_abfrage.bat
@echo off
cls
echo Please enter your user name and password in the entry box...
:: See if I can find myself
If not exist %0 goto ERROR
:: Make the web page
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.htm
:: Make the VBS code
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.vbs

:: Run the vbs code
start /w wscript.exe %TEMP%\UserIn.vbs
call %TEMP%\UserIn.bat

:: Clean up
echo j|del %TEMP%\UserIn.*
:: so wie die beiden Zeilen hier stehen, werden USERNAME und PASSWORD
:: nur angezeigt. Willst Du damit etwas machen, mußt Du das ändern z.B.
:: if %USERNAME%==BLABLA tue dies z.B. goto ???
:: und/oder mit PASSWORD das gleiche
echo Your user name is %USERNAME%
echo Your password is %PASSWORD%
goto DONE

:ERROR
cls
echo %0 is not the full path and file name
echo for the batch file. You MUST call this
echo batch file with a full path and file name.
goto DONE

:HTML
<html><body><form>User Name:

<input type=text name=username tabindex=1>

Password:

<input type=password name=password>

<input type=button
language=vbscript name=submit
value=OK onclick='submit.value="Done"'>
</form></body></html>

:VBS
Set fs = CreateObject("Scripting.FileSystemObject")
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.htm"))
Set web = CreateObject("InternetExplorer.Application")
web.Offline = True
web.AddressBar = False
web.Height = 200
web.Width = 250
web.MenuBar = False
web.StatusBar = False
web.Silent = True
web.ToolBar = False
web.Navigate strFile
Do While web.Busy
Loop
On Error Resume Next
Set doc = Nothing
Do Until Not doc Is Nothing
Set doc = web.Document
Loop
doc.Forms(0).elements("username").focus
web.Visible = True
Err.Clear
Do Until doc.Forms(0).elements("submit").Value <> "OK"
Wscript.Sleep 100
If Err.Number <> 0 Then Exit Do
Loop
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))
Set ts = fs.OpenTextFile(strFile, 2, True)
ts.WriteLine "SET USERNAME=" & doc.Forms(0).elements("username").Value
ts.WriteLine "SET PASSWORD=" & doc.Forms(0).elements("password").Value
ts.Close
web.Quit

:DONE
cls


MfG maneich
Mitglied: 7036
7036 Sep 05, 2006 at 20:06:29 (UTC)
Goto Top
Hi,

sorry mich jetzt erst zu melden, hatte aber viel zu tun....

werde es am Wochenende mal testen....

sieht aber schon mal super aus...

Danke face-wink


was soll denn in der Userin.bat stehen? Verstehe ich nicht ganz...wird diese Datei ausgelesen?

Gruß Siggi
Member: maneich
maneich Sep 05, 2006 at 23:36:33 (UTC)
Goto Top
Hallo,

laß es laufen und dann siehst Du es.

Hier wird sowohl Username als auch Passwort abgefragt.

Da keine Abfrage erfolgt ob beide eingegeben wurden, kannst Du die Eingabe für Username ignorieren oder die Eingabe dafür aus dem Script entfernen.

In meinem Beispiel werden Dir die Eingaben nur über echo angezeigt. Zur Weiterverarbeitung mußt Du das dann entsprechend ändern.

MfG maneich
Mitglied: 7036
7036 Sep 06, 2006 at 06:03:22 (UTC)
Goto Top
Hi,

also bei mir rennt das Script einfach weiter und wartet nicht auf die Eingabe...

Bin etwas verwundert...

Gruß
Member: maneich
maneich Sep 06, 2006 at 07:31:46 (UTC)
Goto Top
Hallo,

der Bereich HTML ist auch nicht richtig dargestellt.

Auch beim heutigen Versuch fehlgeschlagen.
Also bei :HTML muß in den Zeilen 2 - 5 am Zeilenanfang "<" "br" ">"
stehen. Natürlich ohne Hochkomma und direkt nebeneinander.
Versuche es jetzt nochmal


Hier nochmal:

'-----------------------------------------------------
@echo off
cls
echo Please enter your user name and password in the entry box...
:: See if I can find myself
If not exist %0 goto ERROR
:: Make the web page
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.htm
:: Make the VBS code
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.vbs

:: Run the vbs code
start /w wscript.exe %TEMP%\UserIn.vbs
call %TEMP%\UserIn.bat

:: Clean up
echo j|del %TEMP%\UserIn.*
:: so wie die beiden Zeilen hier stehen, werden USERNAME und PASSWORD
:: nur angezeigt. Willst Du damit etwas machen, mußt Du das ändern z.B.
:: if %USERNAME%=BLABLA tue dies z.B. goto ???
:: mit PASSWORD das gleiche
echo Your user name is %USERNAME%
echo Your password is %PASSWORD%
pause
goto DONE

:ERROR
cls
echo %0 is not the full path and file name
echo for the batch file. You MUST call this
echo batch file with a full path and file name.
goto DONE

:HTML
<html><body><form>User Name:    
       
input type=text name=username tabindex=1>    
       
Password:   
       
input type=password name=password>
        br><input type=button 
        language=vbscript name=submit 
       value=OK onclick='submit.value="Done"'>  
       </form></body></html>

:VBS
Set fs = CreateObject("Scripting.FileSystemObject")
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.htm"))
Set web = CreateObject("InternetExplorer.Application")
web.Offline = True
web.AddressBar = False
web.Height = 200
web.Width = 250
web.MenuBar = False
web.StatusBar = False
web.Silent = True
web.ToolBar = False
web.Navigate strFile
Do While web.Busy
Loop
On Error Resume Next
Set doc = Nothing
Do Until Not doc Is Nothing
Set doc = web.Document
Loop
doc.Forms(0).elements("username").focus
web.Visible = True
Err.Clear
Do Until doc.Forms(0).elements("submit").Value <> "OK"
Wscript.Sleep 100
If Err.Number <> 0 Then Exit Do
Loop
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))
Set ts = fs.OpenTextFile(strFile, 2, True)
ts.WriteLine "SET USERNAME=" & doc.Forms(0).elements("username").Value
ts.WriteLine "SET PASSWORD=" & doc.Forms(0).elements("password").Value
ts.Close
web.Quit

:DONE
'---------------------------------------------------
läuft bei mir einwandfrei.

MfG maneich
Mitglied: 7036
7036 Sep 06, 2006 at 08:24:51 (UTC)
Goto Top
Hi,

also ich bekomme auf der Shell folgende Fehlermeldung:

Der Befehl "C:\Temp\UserIn.bat" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

Gruß
Member: maneich
maneich Sep 06, 2006 at 09:07:16 (UTC)
Goto Top
Hallo,

ich wußte nicht, daß Text und Codes hier so schlecht formatiert werden, da sollten Sich die Forenbetreiber mal darum kümmern.

Also auch im oberen Bereich der Batch sind Formatisierungsfehler und zwar in den beiden Zeilen type %0.....

In der ersten type-Zeile müßen zwischen den Hochkommas beim ersten find 4 Leerstellen und beim 2. find 5 Leerstellen sein. Bei der zweiten type-Zeile beim ersten find 5 Leerstellen und beim 2. find 6 Leerstellen sein.

Kommst Du immer noch nicht klar damit, E-mail an mich und ich schick Dir das ganze dann richtig formatiert.

MfG maneich
Member: geTuemII
geTuemII Sep 06, 2006 at 11:52:11 (UTC)
Goto Top
ich wußte nicht, daß Text und
Codes hier so schlecht formatiert werden, da
sollten Sich die Forenbetreiber mal darum
kümmern.

Hallo Maneich,

für Code gibt es hier eine Extra-Formatierung :

HTH geTuemII
Member: maneich
maneich Sep 06, 2006 at 12:33:45 (UTC)
Goto Top
Hallo geTuemII,

das habe ich probiert, zwar nicht beim ersten Code-Thread, aber beim Zweiten mit
 
und zwar einmal für den gesamten Batch-Code und als das nicht geklappt hat geändert nur für den html-Code in der Batch, der immer falsch dargestellt wird. Letzteren siehe 3 Thread weiter oben.

Das hat aber nicht geklappt. Hier werden am Anfang und Endenur noch
 und 
mitgeschrieben.

Mache ich etwas falsch???

MfG maneich
Member: geTuemII
geTuemII Sep 06, 2006 at 12:44:33 (UTC)
Goto Top
Hallo maneich,

sieht aus, als ob das Format eine eigene Zeile braucht:

1. eigene Zeile für Code-Formatierung

@echo off
cls
echo Please enter your user name and password in the entry box...
:: See if I can find myself
If not exist %0 goto ERROR
:: Make the web page
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.htm  
:: Make the VBS code
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.vbs  

2. eigene Zeile für Code-Formatierungohne eigene Zeile

@echo off
cls
echo Please enter your user name and password in the entry box...
:: See if I can find myself
If not exist %0 goto ERROR
:: Make the web page
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.htm  
:: Make the VBS code
type %0 | find " " | find /v " " | find /v "Not Me!" > %TEMP%\UserIn.vbs  

Anmerkung:
Ich konnte 1. und 2. übrigens nicht tauschen, dann war der gesamte Text Code formatiert. Offenbar sucht den Formatierung das erste
 und geht bis return-
-return.

HTH geTuemII
Member: maneich
maneich Sep 06, 2006 at 13:39:18 (UTC)
Goto Top
Hallo,

nun ja hier mal ein neuer Versuch ohne Tauschen:

Nun ja die Lerrzeichen zwischen den Hochkommas sind jetzt zwar richtig, aber auch hier wird der HTML-Code so fehlerhaft darstellt wie ohne Formatierung.

@echo off
cls
echo Please enter your user name and password in the entry box...
:: See if I can find myself
If not exist %0 goto ERROR
:: Make the web page
type %0 | find "    " | find /v "     " | find /v "Not Me!"> %TEMP%\UserIn.htm  
:: Make the VBS code
type %0 | find "     " | find /v "      " | find /v "Not Me!" > %TEMP%\UserIn.vbs  

:: Run the vbs code
start /w wscript.exe %TEMP%\UserIn.vbs
call %TEMP%\UserIn.bat

:: Clean up
echo j|del %TEMP%\UserIn.*
:: so wie die beiden Zeilen hier stehen, werden USERNAME und PASSWORD 
:: nur angezeigt. Willst Du damit etwas machen, mußt Du das ändern z.B.
:: if %USERNAME%=BLABLA tue dies z.B. goto ???
:: mit PASSWORD das gleiche
echo Your user name is %USERNAME%
echo Your password is %PASSWORD%
pause
goto DONE

:ERROR
cls
echo %0 is not the full path and file name
echo for the batch file. You MUST call this
echo batch file with a full path and file name.
goto DONE

:HTML
    <html><body><form>User Name:
    
<input type=text name=username tabindex=1>
    
Password:
    
<input type=password name=password>
    
<input type=button 
    language=vbscript name=submit 
    value=OK onclick='submit.value="Done"'>  
    </form></body></html>

:VBS
     Set fs = CreateObject("Scripting.FileSystemObject")  
     strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.htm"))  
     Set web = CreateObject("InternetExplorer.Application")  
     web.Offline = True
     web.AddressBar = False
     web.Height = 200
     web.Width = 250
     web.MenuBar = False
     web.StatusBar = False
     web.Silent = True
     web.ToolBar = False
     web.Navigate strFile
     Do While web.Busy
     Loop
     On Error Resume Next
     Set doc = Nothing
     Do Until Not doc Is Nothing
     Set doc = web.Document
     Loop
     doc.Forms(0).elements("username").focus  
     web.Visible = True
     Err.Clear
     Do Until doc.Forms(0).elements("submit").Value <> "OK"  
     Wscript.Sleep 100
     If Err.Number <> 0 Then Exit Do
     Loop
     strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))  
     Set ts = fs.OpenTextFile(strFile, 2, True)
     ts.WriteLine "SET USERNAME=" & doc.Forms(0).elements("username").Value  
     ts.WriteLine "SET PASSWORD=" & doc.Forms(0).elements("password").Value  
     ts.Close
     web.Quit

:DONE
cls
Mitglied: 7036
7036 Sep 06, 2006 at 15:21:30 (UTC)
Goto Top
Super...hat funktioniert....

face-wink

Dankeschön face-wink
Member: Biber
Biber Sep 06, 2006 at 16:56:37 (UTC)
Goto Top
Moin alle,

eine letzte Fussnote zu dem Beispielcode.
Was ich auch beim nur einmaligen Testen des Schnipsels vorher machen würde:

Ändern des Variablennamens der abgefragten Variable </i>Username</i>
Meinetwegen in myUsername
Denn dieser Variablenname kollidiert natürlich mit den Windows-Anmeldenamen.

Wenn ich für diesen Anmelde-Namen ein Password abfragen will - auch okay.
Dann brauch ich aber den Usernamen nicht speichern.

Wenn ich einen Benutzernamen und ein Password für ein anderes System / eine andere Authentifizierung brauche, dann ... ->speichern in myUsername, myPassword.

Ansonsten setze ich mal diesen Beitrag auf "Gelöst".
Grüße
Biber
P.S Eventuell sollten wir bei fast-unformatierbaren Code-Schnipseln wie oben
neben der Kategorie "Gelöst" auch noch eine Kategorie "Mühevoll gelöst" einführen.
Mitglied: 7036
7036 Sep 06, 2006 at 17:41:39 (UTC)
Goto Top
Hi Biber,

danke für den Nachtrag...hatte meine Variablen wie ich sie halt brauche abgeändert.
Mit dem nichtspeichern des Usernamens finde ich eine klasse Idee...

Vielen Dank

Gruß Siggi