| delorie.com/archives/browse.cgi | search |
| From: | "Ben Davis" <ben AT vjpoole DOT freeserve DOT co DOT uk> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: question about password coding |
| Date: | Tue, 4 Apr 2000 11:39:28 +0100 |
| Organization: | Customer of Planet Online |
| Lines: | 49 |
| Message-ID: | <8ccgus$fc4$1@news8.svr.pol.co.uk> |
| References: | <38E92F15 DOT 459B04 AT mindspring DOT com> |
| NNTP-Posting-Host: | modem-70.americium.dialup.pol.co.uk |
| X-Trace: | news8.svr.pol.co.uk 954844956 15748 62.136.67.70 (4 Apr 2000 10:42:36 GMT) |
| NNTP-Posting-Date: | 4 Apr 2000 10:42:36 GMT |
| X-Complaints-To: | abuse AT theplanet DOT net |
| X-Newsreader: | Microsoft Outlook Express 4.72.3110.5 |
| X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
james archer wrote in message <38E92F15 DOT 459B04 AT mindspring DOT com>...
>Anyone happen to have a routine that will let the user enter a password
>with the letters represented by *s, that will send the input to a
>string?
It's not hard to write one. Here is one which will work with getch() and
putch() calls:
/* pw must be at least max_chars+1 bytes (for the null at end)
Returns 0 on success, 1 on failure (if user presses Esc) */
int input_password(char *pw, int max_chars) {
int l = 0;
char c, *p = pw;
*p = 0;
for (;;) {
c = getch();
switch (c) {
case '\b':
if (l) {
*(--p) = 0;
putch('\b');
putch(' ');
putch('\b');
}
break;
case '\r':
putch('\r');
putch('\n');
return 0;
case '\e':
putch('\r');
putch('\n');
return 1;
default:
/* you may want to change this line, depending on what characters are
allowed */
if (c >= ' ' && c <= '~') {
if (l < max_chars) {
*(p++) = c;
*p = 0;
l++;
putch('*');
}
}
}
}
}
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |