libcrypt-util: add superficial validator for UNIX hashed password strings

This commit is contained in:
Lennart Poettering 2019-11-13 23:28:05 +01:00
parent 42f3b2f975
commit 64aa2622a3
2 changed files with 13 additions and 0 deletions

View File

@ -73,3 +73,14 @@ int make_salt(char **ret) {
return 0;
#endif
}
bool hashed_password_valid(const char *s) {
/* Returns true if the specified string is a 'valid' hashed UNIX password, i.e. if starts with '$' or
* with '!$' (the latter being a valid, yet locked password). */
if (isempty(s))
return false;
return STARTSWITH_SET(s, "$", "!$");
}

View File

@ -18,3 +18,5 @@
#include <stdlib.h>
int make_salt(char **ret);
bool hashed_password_valid(const char *s);