Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
secpwd.c File Reference
#include "secutil.h"

Go to the source code of this file.

Defines

#define QUIET_FGETS   fgets

Functions

static void echoOff (int fd)
static void echoOn (int fd)
char * SEC_GetPassword (FILE *input, FILE *output, char *prompt, PRBool(*ok)(char *))
PRBool SEC_CheckPassword (char *cp)
PRBool SEC_BlindCheckPassword (char *cp)

Define Documentation

#define QUIET_FGETS   fgets

Definition at line 61 of file secpwd.c.


Function Documentation

static void echoOff ( int  fd) [static]

Definition at line 64 of file secpwd.c.

{
#if defined(XP_UNIX) && !defined(VMS)
    if (isatty(fd)) {
       struct termios tio;
       tcgetattr(fd, &tio);
       tio.c_lflag &= ~ECHO;
       tcsetattr(fd, TCSAFLUSH, &tio);
    }
#endif
}
static void echoOn ( int  fd) [static]

Definition at line 76 of file secpwd.c.

{
#if defined(XP_UNIX) && !defined(VMS)
    if (isatty(fd)) {
       struct termios tio;
       tcgetattr(fd, &tio);
       tio.c_lflag |= ECHO;
       tcsetattr(fd, TCSAFLUSH, &tio);
    }
#endif
}

Definition at line 154 of file secpwd.c.

{
    if (cp != NULL) {
       return PR_TRUE;
    }
    return PR_FALSE;
}
PRBool SEC_CheckPassword ( char *  cp)

Definition at line 133 of file secpwd.c.

{
    int len;
    char *end;

    len = PORT_Strlen(cp);
    if (len < 8) {
       return PR_FALSE;
    }
    end = cp + len;
    while (cp < end) {
       unsigned char ch = *cp++;
       if (!((ch >= 'A') && (ch <= 'Z')) &&
           !((ch >= 'a') && (ch <= 'z'))) {
           /* pass phrase has at least one non alphabetic in it */
           return PR_TRUE;
       }
    }
    return PR_FALSE;
}
char* SEC_GetPassword ( FILE input,
FILE output,
char *  prompt,
PRBool(*)(char *)  ok 
)

Definition at line 88 of file secpwd.c.

{
#if defined(_WINDOWS)
    int isTTY = (input == stdin);
#define echoOn(x)
#define echoOff(x)
#else
    int infd  = fileno(input);
    int isTTY = isatty(infd);
#endif
    char phrase[200] = {'\0'};      /* ensure EOF doesn't return junk */

    for (;;) {
       /* Prompt for password */
       if (isTTY) {
           fprintf(output, "%s", prompt);
            fflush (output);
           echoOff(infd);
       }

       QUIET_FGETS ( phrase, sizeof(phrase), input);

       if (isTTY) {
           fprintf(output, "\n");
           echoOn(infd);
       }

       /* stomp on newline */
       phrase[PORT_Strlen(phrase)-1] = 0;

       /* Validate password */
       if (!(*ok)(phrase)) {
           /* Not weird enough */
           if (!isTTY) return 0;
           fprintf(output, "Password must be at least 8 characters long with one or more\n");
           fprintf(output, "non-alphabetic characters\n");
           continue;
       }
       return (char*) PORT_Strdup(phrase);
    }
}

Here is the call graph for this function: