- /******************************************************************************
- * (C) 2019 ECKELMANN AG INDUSTRIEAUTOMATION, WIESBADEN
- *******************************************************************************
- *
- * Author schenk, ECKELMANN AG
- * Date 20.02.2019
- *
- ******************************************************************************/
- #include <sys/types.h>
- #include <pwd.h>
- #include <shadow.h>
- #include <crypt.h>
- #include <string.h>
- #include <stdio.h>
- #define ERR_NO_ERROR 0
- #define ERR_PASSWORD_MISMATCH 1
- #define ERR_USER_DOES_NOT_EXIST 2
- #define ERR_NO_PERMISSION 3
- #define ERR_UNKNOWN 4
- int system_authentificate_user (const char*username, const char*password)
- {
- struct passwd*pw;
- struct spwd*sp;
- char*encrypted, *theGoodHash;
- int result=ERR_UNKNOWN;
- pw = getpwnam (username);
- endpwent();
- if (!pw) return ERR_USER_DOES_NOT_EXIST;
- sp = getspnam (pw->pw_name);
- endspent();
- if (sp)
- theGoodHash = sp->sp_pwdp;
- else
- theGoodHash = pw->pw_passwd;
- if (NULL == theGoodHash){
- return ERR_NO_PERMISSION;
- }
- encrypted = crypt (password, theGoodHash);
- result = ERR_NO_ERROR;
- }
- else{
- result = ERR_PASSWORD_MISMATCH;
- }
- return result;
- }
- int main(int argc, char *argv[])
- {
- int result;
- if( argc < 3){
- return 3;
- }
- const char* user= argv[1];
- const char* pw= argv[2];
- result = system_authentificate_user( user, pw);
- if( result == ERR_NO_ERROR ){
- }
- if( result == ERR_PASSWORD_MISMATCH){
- }
- if( result > ERR_PASSWORD_MISMATCH ){
- }
- return result;
- }
authentification example
Posted by Anonymous on Fri 22nd Feb 2019 10:49
raw | new post
view followups (newest first): authentification example by Anonymous
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.