mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
added sha512 password hashing, protocol version 13, server version bump
This commit is contained in:
parent
8344920fdc
commit
53330090fb
6 changed files with 56 additions and 4 deletions
21
servatrice/src/passwordhasher.cpp
Normal file
21
servatrice/src/passwordhasher.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "passwordhasher.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <gcrypt.h>
|
||||
|
||||
QString PasswordHasher::computeHash(const QString &password, const QString &salt)
|
||||
{
|
||||
const int algo = GCRY_MD_SHA512;
|
||||
const int rounds = 1000;
|
||||
|
||||
QByteArray passwordBuffer = (salt + password).toAscii();
|
||||
int hashLen = gcry_md_get_algo_dlen(algo);
|
||||
char hash[hashLen], tmp[hashLen];
|
||||
gcry_md_hash_buffer(algo, hash, passwordBuffer.data(), passwordBuffer.size());
|
||||
for (int i = 1; i < rounds; ++i) {
|
||||
memcpy(tmp, hash, hashLen);
|
||||
gcry_md_hash_buffer(algo, hash, tmp, hashLen);
|
||||
}
|
||||
return salt + QString(QByteArray(hash, hashLen).toBase64());
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue