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
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
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 311112
Url: https://administrator.de/forum/einzelne-zeilen-in-txt-datei-speichern-und-auslesen-311112.html
Ausgedruckt am: 17.04.2025 um 17:04 Uhr
7 Kommentare
Neuester Kommentar

Hi
Regards
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

You better learn a real programming language
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.
If you only want to "learn" batch with this kind of task, OK.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@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
Moin highload,
just as a marginal note, I would recommend in your sample to change line #31
From :
To:
%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
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

Thanks, modified above.

dass dann das programm das bestehende passwort überschreibt?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@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