noah1400
Goto Top

Einzelne Zeilen in txt Datei speichern und auslesen

Liebe Forum-Mitglieder
Ich habe da so eine Frage:

Ich bin gerade dabei ein PW abfrage mit Batch zu machen.
Es sollen mehrere Passwörter in einer .txt Datei gespeichert werden.
Jedes in einer anderen Zeile.
Und dann soll das Programm die einzelnen zeilen überprüfen.

Wie funktioniert das?
Danke im vorraus.

Lg Noah

Content-Key: 311112

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

Ausgedruckt am: 19.03.2024 um 02:03 Uhr

Mitglied: 129813
129813 28.07.2016 aktualisiert um 12:12:36 Uhr
Goto Top
Hi
Es sollen mehrere Passwörter in einer .txt Datei gespeichert werden.
oh my god ... in todays security needs a nogo. Don't do that!

Regards
Mitglied: noah1400
noah1400 28.07.2016 um 12:21:55 Uhr
Goto Top
Zitat von @129813:

Hi
Es sollen mehrere Passwörter in einer .txt Datei gespeichert werden.
oh my god ... in todays security needs a nogo. Don't do that!

Regards
Lieber highload
Ich weis das was ich tue nicht ganz sicher istface-smile
aber ich arbeite schon an einer verschlüsselung.
LG noah
Mitglied: 129813
Lösung 129813 28.07.2016 aktualisiert um 12:39:59 Uhr
Goto Top
You better learn a real programming language face-wink than investing time for such a thing in Batch. Passwords in Batch will never be secure.

If you only want to "learn" batch with this kind of task, OK.
@echo off
set "passfile=A:\passfile.txt"  
:START
cls
echo.
echo Choose from the following possibilities
echo.
echo [1] Create password for current user
echo.
echo [2] Check password for current user
echo.
echo [x] Exit
echo.
choice /c 12X /m "Enter action:"  
goto ACTION%ERRORLEVEL%

:ACTION1
cls
set pass=
set /p "pass=Enter your password:"  
>>"%passfile%" echo %username%=%pass%  
echo Password written to file.
echo.
pause
goto START

:ACTION2
cls
set pass=
set /p "pass=Enter your password:"  
for /f "tokens=1,* delims==" %%a in ('findstr /bic:"%username%=" "%passfile%"') do (  
	if "%%b" == "%pass%" (  
		echo Password for user %username% is correct.
	) else (
		echo Password for user %username% is wrong.
	)
)
echo.
pause
goto START

:ACTION3
exit
Mitglied: Biber
Biber 28.07.2016 aktualisiert um 14:02:15 Uhr
Goto Top
Moin highload,

just as a marginal note, I would recommend in your sample to change line #31
From : ...findstr /bc:"%username%="..
To: ...findstr /bic:"%username%="...

%password% should be case-sensitive - an "username" in an existing "passfile.txt" might be written in a different spelling (upper/lower/mix case).

Grüße
Biber
Mitglied: 129813
129813 28.07.2016 um 14:08:07 Uhr
Goto Top
Thanks, modified above.
Mitglied: noah1400
noah1400 29.07.2016 um 16:38:48 Uhr
Goto Top
Hallo Biber
Kann man auch machen dass wenn man ein Passwort erstellen will aber für den Benutzer schon eines gesetzt ist dass dann das programm das bestehende passwort überschreibt?

Grüße
Noah
Mitglied: 129813
129813 29.07.2016 aktualisiert um 18:06:10 Uhr
Goto Top
dass dann das programm das bestehende passwort überschreibt?
@echo off
set "passfile=A:\passfile.txt"  
:START
cls
echo.
echo Choose from the following possibilities
echo.
echo [1] Create password for current user
echo.
echo [2] Check password for current user
echo.
echo [x] Exit
echo.
choice /c 12X /m "Enter action:"  
goto ACTION%ERRORLEVEL%

:ACTION1
cls
set pass=
set /p "pass=Enter your password:"  
findstr /bic:"%username%=" "%passfile%" >nul 2>&1 && (  
  >"%passfile%"  (for /f "usebackq tokens=1,* delims==" %%a in ("%passfile%") do (  
        if /i "%%a" == "%username%" (  
           echo %username%=%pass%
        ) else (echo %%a=%%b)
    ))
) || (
    >>"%passfile%" echo %username%=%pass%  
)
echo Password written to file.
echo.
pause
goto START

:ACTION2
cls
set pass=
set /p "pass=Enter your password:"  
for /f "tokens=1,* delims==" %%a in ('findstr /bic:"%username%=" "%passfile%"') do (  
	if "%%b" == "%pass%" (  
		echo Password for user %username% is correct.
	) else (
		echo Password for user %username% is wrong.
	)
)
echo.
pause
goto START

:ACTION3
exit