Autor Beitrag
DELPHIn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Windows Vista
Delphi 2007 für Win 32 Prof.
BeitragVerfasst: Di 19.10.04 21:59 
Hallo zusammen,

ich möchte bei einem beliebigem String der möglicherweise als Passwort dienen soll die Anzahl der Bits errechnen.
Wie gehe ich da vor?
Ich habe diese Funktion in einem Programm gesehen (KeePass Passwort Safe) und möchte nur erfahren wie das geht.
Reines Zusammenzählen scheint es nicht zu sein da der String 'd' 5 bits ergibt und '2' 4 bits sind aber 'd2' zusammen dann 11 bits sind.
Stehe da momentan auf dem Schlauch!

Kann man die Sicherheit eines Passworts so überhaupt berechnen denn ein solches soll doch möglichst viele Sonderzeichen, Groß- und Keinschreibung und Zahlen enthalten und das wird hierbei doch sicher nicht berücksichtigt.
Gibt es da eine Methode für?

Nebenbei: kenn jemand eine einfache Function oder auch Komponente, die beliebig lange und komplexe Kennwörter zurückgibt (Passwortgenerator)?

Danke

DELPHIn

_________________
DELPHIn
=> Errare humanum est
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Mi 20.10.04 01:20 
Ich habe mal einen Passwortgenerator geschrieben, der folgendermaßen funktionierte:
Das Programm erzeugt eine Zufallszahl (für Zeichen zb. zwischen 33 und 128), diese Zahl stellt dann den ASCII-Code eines Zeichens dar. Diese Zahl wandelst du um in ein Zeichen. Das machst du so oft, bis du die gewünschte Länge erreicht hast. Dabei fügst du jedes mal das Zeichen in den String hinzu, in dem das Passwort gespeichert ist. Und so hast du dann dein Zufällig erzeugtest Passwort.
Ich hoffe, dass du das einigermaßen verstehen kannst. Wenn nicht kann ich dir auch noch weitere Fragen beantworten.
Kroni
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 20.10.04 19:28 
Die Funktion prüft, wie viele Bits in den möglichen Zeichen-Bereichen drin sind:

Zahlen: 10 -> 4 Bits
Kleinbuchstaben: 26 -> 5 Bits
Kleinbuchstaben, Großbuchstaben, Zahlen, Sonderzeichen: 96 -> 7 Bits

Die Funktion geht nun davon aus, dass nur Zahlen in einem PW vorkommen:
'2' -> 4 Bits
Findet sie an erster Stelle einen Kleinbuchstaben, wird der 2. Bereich angenommen
'd' -> 5 Bits
Hat das PW nun 2 Zeichen, so kommt nochmal dazu, dass Kombinationen geprüft werden:
'd5' -> 5 Bits \ 4 Bits, da aber theoretisch das erste Zeichen alles sein könnte -> 7 Bits \ 4 Bits -> 11 Bits

IMHO.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
DELPHIn Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Windows Vista
Delphi 2007 für Win 32 Prof.
BeitragVerfasst: Fr 22.10.04 15:41 
Vielen Dank, jetzt habe ich versanden und die Funktion ist auch fertig.
Hier für interessierte eine erste Version:

ausblenden volle Höhe Quelltext
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:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
function THaupt.Passworttest(pszPassword : string): integer;
  const
  CHARSPACE_ESCAPE = 60;
  CHARSPACE_ALPHA = 26;
  CHARSPACE_NUMBER = 10;
  CHARSPACE_SIMPSPECIAL = 16;
  CHARSPACE_EXTSPECIAL = 17;
  CHARSPACE_HIGH = 112;
  var
  i, dwLen, dwCharSpace, dwBits : integer;
  bChLower, bChUpper, bChNumber, bChSimpleSpecial, bChExtSpecial, bChHigh, bChEscape : boolean;
  tch : string;
  dblBitsPerChar : double;
  x, y : real;
begin
  bChLower := FALSE;
  bChUpper := FALSE;
  bChNumber := FALSE;
  bChSimpleSpecial := FALSE;
  bChExtSpecial := FALSE;
  bChHigh := FALSE;
  bChEscape := FALSE;

  if pszPassword = '' then
  begin
    Result := 0;
    exit;
  end;

  dwLen := length(pszPassword);
  if dwLen = 0 then
  begin
    Result := 0; // Zero bits of information :)
    exit;
  end;

  for i := 1 to dwLen do // Get character types
  begin
    tch := copy(pszPassword,i,1);
    if tch < ' ' then
      bChEscape := TRUE;
    if (tch >= 'A') and (tch <= 'Z') then
      bChUpper := TRUE;
    if  (tch >= 'a') and (tch <= 'z') then
      bChLower := TRUE;
    if (tch >= '0') and (tch <= '9') then
      bChNumber := TRUE;
    if (tch >= ' ') and (tch <= '/') then
      bChSimpleSpecial := TRUE;
    if (tch >= ':') and (tch <= '@') then
      bChExtSpecial := TRUE;
    if (tch >= '[') and (tch <= '`') then
      bChExtSpecial := TRUE;
    if (tch >= '{') and (tch <= '~') then
      bChExtSpecial := TRUE;
    if tch > '~' then
      bChHigh := TRUE;
  end;

  dwCharSpace := 0;
  if bChEscape = TRUE then
    dwCharSpace := dwCharSpace + CHARSPACE_ESCAPE;
  if bChUpper = TRUE then
    dwCharSpace := dwCharSpace + CHARSPACE_ALPHA;
  if bChLower = TRUE then
    dwCharSpace := dwCharSpace + CHARSPACE_ALPHA;
  if bChNumber = TRUE then
    dwCharSpace := dwCharSpace + CHARSPACE_NUMBER;
  if bChSimpleSpecial = TRUE then
    dwCharSpace := dwCharSpace + CHARSPACE_SIMPSPECIAL;
  if bChExtSpecial = TRUE then
    dwCharSpace := dwCharSpace + CHARSPACE_EXTSPECIAL;
  if bChHigh = TRUE then
    dwCharSpace := dwCharSpace + CHARSPACE_HIGH;

  if dwCharSpace = 0 then
  begin
    Result := 0;
    exit;
  end;

  dblBitsPerChar := ln(dwCharSpace) / ln(2.00);
  x := dblBitsPerChar * dwLen;
  y := frac(x);
  if y > 0 then
    x := x - y + 1;
  dwBits := round(x);

  Result := dwBits;
end;

_________________
DELPHIn
=> Errare humanum est
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 22.10.04 17:47 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  if pszPassword = '' then
  begin
    Result := 0;
    exit;
  end;

  dwLen := length(pszPassword);
  if dwLen = 0 then
  begin
    Result := 0; // Zero bits of information :)
    exit;
  end;


Eine der beiden Prüfungen kann entfallen, da du effektiv zweimal das gleiche prüfst ...
Würde dafür plädieren, dass du die zweite Prüfung drin lässt, da sie gewohnter in meinen Augen ist.

ausblenden Delphi-Quelltext
1:
    tch := copy(pszPassword,i,1);					

Geht einfacher mit
ausblenden Delphi-Quelltext
1:
    tch := pszPassword[1];					


Achso:

Bitte nutz mal die Delphi-Tags in deinem Post. Liest sich einfach besser.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
DELPHIn Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Windows Vista
Delphi 2007 für Win 32 Prof.
BeitragVerfasst: Fr 22.10.04 22:39 
Danke, schon umgesetzt.
Bin jetzt dabei den Passwort-Generator zu schreiben, aber heute wohl nicht mehr lange. Das Bett ruft.

_________________
DELPHIn
=> Errare humanum est