From 04b8068979527a501496b46ba65f208571de499f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 26 Sep 2018 21:06:56 +0200 Subject: [PATCH] rename password functions to match PHP. --- src/bind_faction.c | 2 +- src/kernel/faction.c | 2 +- src/kernel/faction.test.c | 2 +- src/kernel/save.c | 4 ++-- src/kernel/save.test.c | 4 ++-- src/laws.c | 2 +- src/util/password.c | 2 +- src/util/password.h | 2 +- src/util/password.test.c | 4 ++-- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bind_faction.c b/src/bind_faction.c index 850679933..632fcec3d 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -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; } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 7284db52d..6e85988f4 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -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)); } diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 04a2b1e97..9cd5d9de8 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -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")); diff --git a/src/kernel/save.c b/src/kernel/save.c index 922fcc24f..e7cb90d2a 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -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; } diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 036ad00c5..d9ba52862 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -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); diff --git a/src/laws.c b/src/laws.c index fe97931ad..d9e05917a 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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; diff --git a/src/util/password.c b/src/util/password.c index a7e14c98b..61ae8f2a0 100644 --- a/src/util/password.c +++ b/src/util/password.c @@ -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]; diff --git a/src/util/password.h b/src/util/password.h index 61abc588f..7309e0c0e 100644 --- a/src/util/password.h +++ b/src/util/password.h @@ -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); diff --git a/src/util/password.test.c b/src/util/password.test.c index f22ef5971..7ce2d0682 100644 --- a/src/util/password.test.c +++ b/src/util/password.test.c @@ -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"));