forked from github/server
rename password functions to match PHP.
This commit is contained in:
parent
e462529596
commit
04b8068979
9 changed files with 12 additions and 12 deletions
|
@ -452,7 +452,7 @@ static int tolua_faction_set_password(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||||
const char * passw = tolua_tostring(L, 2, 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ faction *addfaction(const char *email, const char *password,
|
||||||
f->flags = FFL_ISNEW|FFL_PWMSG;
|
f->flags = FFL_ISNEW|FFL_PWMSG;
|
||||||
|
|
||||||
if (password) {
|
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));
|
ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ static void test_check_passwd(CuTest *tc) {
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
f = test_create_faction(NULL);
|
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, "password"));
|
||||||
CuAssertTrue(tc, !checkpasswd(f, "assword"));
|
CuAssertTrue(tc, !checkpasswd(f, "assword"));
|
||||||
CuAssertTrue(tc, !checkpasswd(f, "PASSWORD"));
|
CuAssertTrue(tc, !checkpasswd(f, "PASSWORD"));
|
||||||
|
|
|
@ -924,7 +924,7 @@ static void read_password(gamedata *data, faction *f) {
|
||||||
if (name[0] == '$' && data->version == BADCRYPT_VERSION) {
|
if (name[0] == '$' && data->version == BADCRYPT_VERSION) {
|
||||||
char * pass = getpasswd(f->no);
|
char * pass = getpasswd(f->no);
|
||||||
if (pass) {
|
if (pass) {
|
||||||
faction_setpassword(f, password_encode(pass, PASSWORD_DEFAULT));
|
faction_setpassword(f, password_hash(pass, PASSWORD_DEFAULT));
|
||||||
free(pass); /* TODO: remove this allocation! */
|
free(pass); /* TODO: remove this allocation! */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -932,7 +932,7 @@ static void read_password(gamedata *data, faction *f) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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;
|
(void)_test_read_password;
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,7 +407,7 @@ static void test_read_password(CuTest *tc) {
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
f = test_create_faction(NULL);
|
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);
|
mstream_init(&data.strm);
|
||||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||||
_test_write_password(&data, f);
|
_test_write_password(&data, f);
|
||||||
|
@ -431,7 +431,7 @@ static void test_read_password_external(CuTest *tc) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
f = test_create_faction(NULL);
|
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);
|
CuAssertPtrNotNull(tc, f->_password);
|
||||||
mstream_init(&data.strm);
|
mstream_init(&data.strm);
|
||||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||||
|
|
|
@ -2135,7 +2135,7 @@ int password_cmd(unit * u, struct order *ord)
|
||||||
cmistake(u, ord, 283, MSG_EVENT);
|
cmistake(u, ord, 283, MSG_EVENT);
|
||||||
str_strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf));
|
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",
|
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
|
||||||
"value", pwbuf));
|
"value", pwbuf));
|
||||||
u->faction->flags |= FFL_PWMSG;
|
u->faction->flags |= FFL_PWMSG;
|
||||||
|
|
|
@ -16,7 +16,7 @@ bool password_is_implemented(cryptalgo_t algo) {
|
||||||
return algo == PASSWORD_PLAINTEXT;
|
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) {
|
if (algo == PASSWORD_BCRYPT) {
|
||||||
char salt[BCRYPT_HASHSIZE];
|
char salt[BCRYPT_HASHSIZE];
|
||||||
static char hash[BCRYPT_HASHSIZE];
|
static char hash[BCRYPT_HASHSIZE];
|
||||||
|
|
|
@ -13,5 +13,5 @@ extern int bcrypt_workfactor;
|
||||||
#define VERIFY_FAIL 1
|
#define VERIFY_FAIL 1
|
||||||
#define VERIFY_UNKNOWN 2
|
#define VERIFY_UNKNOWN 2
|
||||||
int password_verify(const char *hash, const char *passwd);
|
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);
|
bool password_is_implemented(cryptalgo_t algo);
|
||||||
|
|
|
@ -9,7 +9,7 @@ static void test_passwords(CuTest *tc) {
|
||||||
if (password_is_implemented(PASSWORD_BCRYPT)) {
|
if (password_is_implemented(PASSWORD_BCRYPT)) {
|
||||||
int wf = bcrypt_workfactor;
|
int wf = bcrypt_workfactor;
|
||||||
bcrypt_workfactor = 4;
|
bcrypt_workfactor = 4;
|
||||||
hash = password_encode("password", PASSWORD_BCRYPT);
|
hash = password_hash("password", PASSWORD_BCRYPT);
|
||||||
CuAssertPtrNotNull(tc, hash);
|
CuAssertPtrNotNull(tc, hash);
|
||||||
CuAssertIntEquals(tc, '$', hash[0]);
|
CuAssertIntEquals(tc, '$', hash[0]);
|
||||||
CuAssertIntEquals(tc, '2', hash[1]);
|
CuAssertIntEquals(tc, '2', hash[1]);
|
||||||
|
@ -22,7 +22,7 @@ static void test_passwords(CuTest *tc) {
|
||||||
bcrypt_workfactor = wf;
|
bcrypt_workfactor = wf;
|
||||||
}
|
}
|
||||||
if (password_is_implemented(PASSWORD_PLAINTEXT)) {
|
if (password_is_implemented(PASSWORD_PLAINTEXT)) {
|
||||||
hash = password_encode("password", PASSWORD_PLAINTEXT);
|
hash = password_hash("password", PASSWORD_PLAINTEXT);
|
||||||
CuAssertPtrNotNull(tc, hash);
|
CuAssertPtrNotNull(tc, hash);
|
||||||
CuAssertStrEquals(tc, hash, "password");
|
CuAssertStrEquals(tc, hash, "password");
|
||||||
CuAssertIntEquals(tc, VERIFY_OK, password_verify(hash, "password"));
|
CuAssertIntEquals(tc, VERIFY_OK, password_verify(hash, "password"));
|
||||||
|
|
Loading…
Reference in a new issue