rename password functions to match PHP.

This commit is contained in:
Enno Rehling 2018-09-26 21:06:56 +02:00
parent e462529596
commit 04b8068979
9 changed files with 12 additions and 12 deletions

View File

@ -452,7 +452,7 @@ static int tolua_faction_set_password(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char * passw = tolua_tostring(L, 2, 0);
faction_setpassword(self, password_encode(passw, PASSWORD_DEFAULT));
faction_setpassword(self, password_hash(passw, PASSWORD_DEFAULT));
return 0;
}

View File

@ -254,7 +254,7 @@ faction *addfaction(const char *email, const char *password,
f->flags = FFL_ISNEW|FFL_PWMSG;
if (password) {
faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT));
faction_setpassword(f, password_hash(password, PASSWORD_DEFAULT));
ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
}

View File

@ -137,7 +137,7 @@ static void test_check_passwd(CuTest *tc) {
faction *f;
f = test_create_faction(NULL);
faction_setpassword(f, password_encode("password", PASSWORD_DEFAULT));
faction_setpassword(f, password_hash("password", PASSWORD_DEFAULT));
CuAssertTrue(tc, checkpasswd(f, "password"));
CuAssertTrue(tc, !checkpasswd(f, "assword"));
CuAssertTrue(tc, !checkpasswd(f, "PASSWORD"));

View File

@ -924,7 +924,7 @@ static void read_password(gamedata *data, faction *f) {
if (name[0] == '$' && data->version == BADCRYPT_VERSION) {
char * pass = getpasswd(f->no);
if (pass) {
faction_setpassword(f, password_encode(pass, PASSWORD_DEFAULT));
faction_setpassword(f, password_hash(pass, PASSWORD_DEFAULT));
free(pass); /* TODO: remove this allocation! */
}
else {
@ -932,7 +932,7 @@ static void read_password(gamedata *data, faction *f) {
}
}
else {
faction_setpassword(f, (data->version >= CRYPT_VERSION) ? name : password_encode(name, PASSWORD_DEFAULT));
faction_setpassword(f, (data->version >= CRYPT_VERSION) ? name : password_hash(name, PASSWORD_DEFAULT));
}
(void)_test_read_password;
}

View File

@ -407,7 +407,7 @@ static void test_read_password(CuTest *tc) {
test_setup();
f = test_create_faction(NULL);
faction_setpassword(f, password_encode("secret", PASSWORD_DEFAULT));
faction_setpassword(f, password_hash("secret", PASSWORD_DEFAULT));
mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION);
_test_write_password(&data, f);
@ -431,7 +431,7 @@ static void test_read_password_external(CuTest *tc) {
errno = 0;
}
f = test_create_faction(NULL);
faction_setpassword(f, password_encode("secret", PASSWORD_DEFAULT));
faction_setpassword(f, password_hash("secret", PASSWORD_DEFAULT));
CuAssertPtrNotNull(tc, f->_password);
mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION);

View File

@ -2135,7 +2135,7 @@ int password_cmd(unit * u, struct order *ord)
cmistake(u, ord, 283, MSG_EVENT);
str_strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf));
}
faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT));
faction_setpassword(u->faction, password_hash(pwbuf, PASSWORD_DEFAULT));
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
"value", pwbuf));
u->faction->flags |= FFL_PWMSG;

View File

@ -16,7 +16,7 @@ bool password_is_implemented(cryptalgo_t algo) {
return algo == PASSWORD_PLAINTEXT;
}
const char * password_encode(const char * passwd, cryptalgo_t algo) {
const char * password_hash(const char * passwd, cryptalgo_t algo) {
if (algo == PASSWORD_BCRYPT) {
char salt[BCRYPT_HASHSIZE];
static char hash[BCRYPT_HASHSIZE];

View File

@ -13,5 +13,5 @@ extern int bcrypt_workfactor;
#define VERIFY_FAIL 1
#define VERIFY_UNKNOWN 2
int password_verify(const char *hash, const char *passwd);
const char * password_encode(const char *passwd, cryptalgo_t algo);
const char * password_hash(const char *passwd, cryptalgo_t algo);
bool password_is_implemented(cryptalgo_t algo);

View File

@ -9,7 +9,7 @@ static void test_passwords(CuTest *tc) {
if (password_is_implemented(PASSWORD_BCRYPT)) {
int wf = bcrypt_workfactor;
bcrypt_workfactor = 4;
hash = password_encode("password", PASSWORD_BCRYPT);
hash = password_hash("password", PASSWORD_BCRYPT);
CuAssertPtrNotNull(tc, hash);
CuAssertIntEquals(tc, '$', hash[0]);
CuAssertIntEquals(tc, '2', hash[1]);
@ -22,7 +22,7 @@ static void test_passwords(CuTest *tc) {
bcrypt_workfactor = wf;
}
if (password_is_implemented(PASSWORD_PLAINTEXT)) {
hash = password_encode("password", PASSWORD_PLAINTEXT);
hash = password_hash("password", PASSWORD_PLAINTEXT);
CuAssertPtrNotNull(tc, hash);
CuAssertStrEquals(tc, hash, "password");
CuAssertIntEquals(tc, VERIFY_OK, password_verify(hash, "password"));