Example #1
0
/**
 * @brief
 *	Accepts a password string without echoing characters
 *	on the screen
 *
 * @param[out]	passwd - password read from user
 *
 * @return - Error code
 * @retval  -1 - Failure
 * @retval   0 - Success
 *
 */
static int
read_password(char *passwd)
{
	int len;
	char *p;

#ifndef WIN32
	if (system("stty -echo") != 0)
		return -1;

	fgets(passwd, MAX_PASSWORD_LEN, stdin);

	if (system("stty echo") != 0)
		return -1;
#else
	gets_noecho(passwd, MAX_PASSWORD_LEN);
#endif

	len = strlen(passwd);
	p = passwd + len - 1;
	while (*p == '\r' || *p == '\n')
		p--;
	*(p + 1) = 0;

	return 0;
}
Example #2
0
/* Password callback. */
int
ssl_passwd_gui_callback(char *buf, int size)
{
    char *s;

   fprintf(stdout, "\nEnter password for Private Key: ");
   fflush(stdout);
   s = gets_noecho(buf, size);
   fprintf(stdout, "\n");
   fflush(stdout);
   ssl_password_prompted = true;
   return s? (int)strlen(s): 0;
}