home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / muglog.zip / LOGIN.C next >
C/C++ Source or Header  |  1995-05-19  |  2KB  |  114 lines

  1. #define CM_OS2
  2. #define INCL_32
  3.  
  4. #define INCL_DOSFILEMGR
  5. #define INCL_DOSMISC
  6.  
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <upm.h>
  11. #include <os2.h>
  12.  
  13. int GetUseridPassword(char *userid, char* password);
  14. char * _cgetsNoEcho(char *buffer);
  15. void DisplayLogo(void);
  16.  
  17. int main(int argc, char** argv)
  18.    {
  19.    char userid[9];
  20.    char password[9];
  21.    int  i;
  22.  
  23.    DisplayLogo();
  24.    for(i = 0; i < 3; i++)
  25.       {
  26.       if (0 == GetUseridPassword(userid, password))
  27.          return 0;
  28.       printf("3004-007 You entered an invalid login name or password.\r\n");
  29.       }
  30.    return 1;
  31.    } /* main */
  32.  
  33.  
  34. void DisplayLogo(void)
  35.    {
  36.    struct
  37.       {
  38.       ULONG major;
  39.       ULONG minor;
  40.       ULONG revision;
  41.       } ver;
  42.    int i;
  43.  
  44.    DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_REVISION, &ver, sizeof(ver));
  45.  
  46.    if ((ver.major == 20) && (ver.minor == 30))
  47.       {
  48.       ver.major = 30;
  49.       ver.minor = 0;
  50.       }
  51.  
  52.    /* Clear the screen */
  53.  
  54.    for (i = 0; i < 32; i++)
  55.       _cputs("\r\n");
  56.  
  57.    printf("OS/2 Version %d.%d\r\n(c) Copyrights by IBM\r\n", (ver.major/10), ver.minor);
  58.    return;
  59.    } /* DisplayLogo */
  60.  
  61. int GetUseridPassword(char *userid, char* password)
  62.    {
  63.    char inputBuffer[12];
  64.    char *p;                /* Work pointer */
  65.    LSINT LSFAR LSPAS rc;
  66.  
  67.    /* Get userid */
  68.  
  69.    _cputs("login: ");
  70.    inputBuffer[0] = 0x08;   /* Max length of string for userid */
  71.    p = _cgets(inputBuffer);
  72.    strcpy(userid, p);
  73.  
  74.    /* Get password */
  75.  
  76.    _cputs("\r\n");
  77.    _cputs(userid);
  78.    _cputs("'s Password: ");
  79.  
  80.  
  81.    inputBuffer[0] = 0x08;  /* Max length of string for userid */
  82.    p = _cgetsNoEcho(inputBuffer);
  83.    strcpy(password, p);
  84.    _cputs("\r\n");
  85.  
  86.    /* Validate the userid and password with UPM */
  87.  
  88.    strupr(userid);
  89.    strupr(password);
  90.    rc = upmelgn(userid, password, "", UPM_LOCAL, UPM_USER);
  91.    return (UPM_OK == rc) ? 0 : 1;
  92.    } /* GetUseridPassword */
  93.  
  94.  
  95. char * _cgetsNoEcho(char *buffer)
  96.    {
  97.    char *p;
  98.    int   i;
  99.  
  100.    p = buffer+1;
  101.    memset(p,'\0',(int)buffer[0]);
  102.    for(i = 0; i < (int)buffer[0]; i++)
  103.       {
  104.       *p = _getch();
  105.       if ((*p == '\r') || (*p == '\n'))
  106.          {
  107.          *p = '\0';
  108.          return (buffer+1);
  109.          }
  110.       p++;
  111.       }
  112.    return (buffer+1);
  113.    }
  114.