Äquivalent zu MySQL-Password()-Funktion gesucht

aruba-x-x

Erfahrenes Mitglied
Hallo,

bin auf der Suche nach einer Funktion, mit der ich die Password-Funktion von MySQL imitieren kann. Also ich will für ein Passwort den gleichen 16-char-Hash erzeugen.
Vielleicht kann mir da jemand weiterhelfen.
 
Nein, leider nicht, aber trotzdem Danke.
Der Hash bei älteren Versionen von MySQL hat nur 16 Stellen. Ich müsste halt wissen wie der erzeugt wird.
 
Lade Dir den MySQL-Quellcode herunter.
Diese Datei beinhaltet die Funktionalität für die Password() Funktion:
mysql-src/sql/password.c

Ein Auszug der entsprechenden Funktion:


mysql-5.0.21-win-src\mysql-5.0.21\sql\password.c
C++:
/*
    MySQL 4.1.1 password hashing: SHA conversion (see RFC 2289, 3174) twice
    applied to the password string, and then produced octet sequence is
    converted to hex string.
    The result of this function is used as return value from PASSWORD() and
    is stored in the database.
  SYNOPSIS
    make_scrambled_password()
    buf       OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string
    password  IN  NULL-terminated password string
*/

void
make_scrambled_password(char *to, const char *password)
{
}
 
Vielen Dank, ich habs gefunden.

Hier noch das Ergebnis, vielleicht brauchts ja mal noch jemand anders:

Code:
typedef unsigned long ulong;
typedef unsigned char uchar;

void hash_password(ulong *result, const char *password)
{
  register ulong nr=1345345333L, add=7, nr2=0x12345671L;
  ulong tmp;
  for (; *password ; password++)
  {
    if (*password == ' ' || *password == '\t')
      continue;            /* skipp space in password */
    tmp= (ulong) (uchar) *password;
    nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
    nr2+=(nr2 << 8) ^ nr;
    add+=tmp;
  }
  result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
  result[1]=nr2 & (((ulong) 1L << 31) -1L);
  return;
}

void make_scrambled_password(char *to,const char *password)
{
  ulong hash_res[2];
  hash_password(hash_res,password);
  sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
}
 

Neue Beiträge

Zurück