/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <string.h>

#include <descrip.h>
#include <uaidef.h>

#include <starlet.h>

struct itmlst
{
   short int length;
   short int code;
   long int bufadr;
   long int retlenadr;
};

int chkpw(char *un, char *pw)
{
   long int pwd[2],hpwd[2];
   short int salt;
   char encryp;
   struct dsc$descriptor_s undesc,pwdesc;
   struct itmlst items[4] = { {sizeof(salt), UAI$_SALT, (long int)&salt, 0},
                              {sizeof(encryp), UAI$_ENCRYPT, (long int)&encryp, 0},
                              {sizeof(pwd), UAI$_PWD, (long int)&pwd, 0},
                              {0, 0, 0, 0} };
   undesc.dsc$w_length = strlen(un);
   undesc.dsc$b_dtype = DSC$K_DTYPE_T;
   undesc.dsc$b_class = DSC$K_CLASS_S;
   undesc.dsc$a_pointer = un;
   pwdesc.dsc$w_length = strlen(pw);
   pwdesc.dsc$b_dtype = DSC$K_DTYPE_T;
   pwdesc.dsc$b_class = DSC$K_CLASS_S;
   pwdesc.dsc$a_pointer = pw;
   sys$getuai(0, 0, &undesc, &items, 0, 0, 0);
   sys$hash_password(&pwdesc, encryp, salt, &undesc, &hpwd);
   return pwd[0] == hpwd[0] && pwd[1] == hpwd[1];
}

#include <stdio.h>

int main()
{
   printf("%d\n", chkpw("ARNE", "HEMMELIGT"));
   printf("%d\n", chkpw("ARNE", "HEMMELIGT2"));
   printf("%d\n", chkpw("ARNE2", "HEMMELIGT"));
   return 1;
}
