Hash :
c0ad8afc
Author :
Thomas de Grivel
Date :
2024-10-25T16:43:47
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
/* kc3
* Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <errno.h>
#include <pwd.h>
#include <string.h>
#include <unistd.h>
#include "assert.h"
#include "crypt.h"
#include "str.h"
bool * crypt_check_password (const s_str *pass, const s_str *hash,
bool *dest)
{
sw e;
assert(pass);
assert(hash);
assert(dest);
if (crypt_checkpass(pass->ptr.pchar, hash->ptr.pchar)) {
e = errno;
err_write_1("crypt_check_password: ");
err_write_1(strerror(e));
err_write_1("\n");
*dest = false;
}
else
*dest = true;
return dest;
}
s_str * crypt_hash_password (const s_str *pass, s_str *dest)
{
sw e;
char hash[_PASSWORD_LEN] = {0};
assert(pass);
assert(dest);
if (crypt_newhash(pass->ptr.pchar, "bcrypt,a", hash,
sizeof(hash))) {
e = errno;
err_write_1("crypt_hash_password: ");
err_write_1(strerror(e));
err_write_1("\n");
return NULL;
}
return str_init_copy_1(dest, hash);
}