b-free
Goto Top

Passwortgenerator MIT Sonderzeichen auf Batch-Ebene

Hi,

ich hab seit geraumer zeit probiert ein passwortgenerator zu bauen. leider ging das ganze nicht ganz auf. später bekam ich hilfe von einem kumpel und schließlich kam das dabei raus:

@echo off
color 0a
:begin
set pw=
set /P th=Bitte stellen eingeben:
set /A dt=0
:1
set /A dt=%dt%+1
set /A gdp=%random% %%53
if %gdp%==0 (set pw=%pw%`)
if %gdp%==1 (set pw=%pw%q)
if %gdp%==2 (set pw=%pw%w)
if %gdp%==3 (set pw=%pw%e)
if %gdp%==4 (set pw=%pw%r)
if %gdp%==5 (set pw=%pw%t)
if %gdp%==6 (set pw=%pw%z)
if %gdp%==7 (set pw=%pw%u)
if %gdp%==8 (set pw=%pw%i)
if %gdp%==9 (set pw=%pw%o)
if %gdp%==10 (set pw=%pw%p)
if %gdp%==11 (set pw=%pw%a)
if %gdp%==12 (set pw=%pw%s)
if %gdp%==13 (set pw=%pw%d)
if %gdp%==14 (set pw=%pw%f)
if %gdp%==15 (set pw=%pw%g)
if %gdp%==16 (set pw=%pw%h)
if %gdp%==17 (set pw=%pw%j)
if %gdp%==18 (set pw=%pw%k)
if %gdp%==19 (set pw=%pw%l)
if %gdp%==20 (set pw=%pw%y)
if %gdp%==21 (set pw=%pw%x)
if %gdp%==22 (set pw=%pw%c)
if %gdp%==23 (set pw=%pw%v)
if %gdp%==24 (set pw=%pw%b)
if %gdp%==25 (set pw=%pw%n)
if %gdp%==26 (set pw=%pw%m)
if %gdp%==27 (set pw=%pw%0)
if %gdp%==28 (set pw=%pw%1)
if %gdp%==29 (set pw=%pw%2)
if %gdp%==30 (set pw=%pw%3)
if %gdp%==31 (set pw=%pw%4)
if %gdp%==32 (set pw=%pw%5)
if %gdp%==33 (set pw=%pw%6)
if %gdp%==34 (set pw=%pw%7)
if %gdp%==35 (set pw=%pw%8)
if %gdp%==36 (set pw=%pw%9)
if %gdp%==37 (set pw=%pw%})
if %gdp%==38 (set pw=%pw%;)
if %gdp%==39 (set pw=%pw%,)
if %gdp%==40 (set pw=%pw%.)
if %gdp%==41 (set pw=%pw%-)
if %gdp%==42 (set pw=%pw%_)
if %gdp%==43 (set pw=%pw%+)
if %gdp%==44 (set pw=%pw%~)
if %gdp%==45 (set pw=%pw%#)
if %gdp%==46 (set pw=%pw%')  
if %gdp%==47 (set pw=%pw%@)
if %gdp%==48 (set pw=%pw%?)
if %gdp%==49 (set pw=%pw%$)
if %gdp%==50 (set pw=%pw%[)
if %gdp%==51 (set pw=%pw%])
if %gdp%==52 (set pw=%pw%{)
if %dt% lss %th% (goto 1)
echo %pw%
set /P yn=Wollen sie die datei speicher ? J\N :
if %yn%==J (
echo %pw% > Passwort.txt
echo Passwort wurde gespeichert)
if %yn%==j (
echo %pw% > Passwort.txt
echo Passwort wurde gespeichert)
if %yn%==y (
echo %pw% > Passwort.txt
echo Passwort wurde gespeichert)
if %yn%==Y (
echo %pw% > Passwort.txt
echo Passwort wurde gespeichert)
if %yn%==N (
echo Passwort wurde nicht gespeichert)
if %yn%==n (
echo Passwort wurde nicht gespeichert)
echo Beenden???
echo J/N
set /p beenden=
if "%beenden%"=="J" EXIT  
if "%beenden%"=="j" EXIT  
if "%beenden%"=="y" EXIT  
if {{comment_strings:11636036194}}=="Y" EXIT  
goto begin

Bis dann
B-Free

Content-Key: 195841

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

Printed on: April 18, 2024 at 23:04 o'clock

Member: rubberman
rubberman Dec 13, 2012 updated at 22:12:50 (UTC)
Goto Top
Hallo B-free,

ich würde das geringfügig anders angehen face-wink
@echo off &setlocal enabledelayedexpansion
set "pwd="  
set /a "n = 0"  

set /p "n=Anzahl Stellen: "  

set /a "n = !n!" 2>nul  
for /l %%i in (1 1 !n!) do (
  set /a "x = !random! %% 94 + 33"  
  cmd /c exit /b !x!
  set "pwd=!pwd!!=ExitCodeAscii!"  
)

>"passwort.txt" echo(!pwd!  
start "" notepad "passwort.txt"  

Zur Erklärung:
Wie du auf einer ASCII Tabelle deiner Wahl erkennen kannst, hast du im Standardbereich die Zeichen ! (33) bis ~ (126) zur Auswahl.
Die Differenz ergibt 93. Wenn du nun in einer Modulooperation 94 als Divisor zu einer Zufallszahl berechnest, erhältst du eine Zahl zwischen 0 und 93. Dazu das Offset von 33 addieren, und du bewegst dich im Range der druckbaren Standard-ASCII Zeichen.
Die Kommandozeile kennt ein paar kaum dokumentierte Variablen. Eine davon ist %=ExitCodeAscii%. Diese gibt einen Errorlevelwert als ASCII Zeichen zurück. Genau das mache ich mir hier zu Nutze, um die Zeichen des Passworts zu bekommen.

BTW: So etwas wie
if %yn%==y ...
if %yn%==Y ...
kannst du mit Option /i zu
if /i "%yn%"=="y" ...
zusammenfassen.

Grüße
rubberman
Member: B-free
B-free Dec 14, 2012 at 23:04:52 (UTC)
Goto Top
Danke für den tipp.

ist doch noch ein wenig zusammengeschrumpft und vor allem beherrscht er jetzt auch (,),: usw...


Tschau
B-Free
Member: DerWoWusste
DerWoWusste Dec 21, 2012 at 18:40:03 (UTC)
Goto Top
Hi.

Kennst Du schon
net user administrator /random
Password for administrator is: 1l%TgY-Y

?