freelanceprogrammers.org Forum Index » C

Problem with mask password.


View user's profile Post To page top
mcosta@... Posted: Tue Jul 29, 2003 6:37 pm


Joined: 29 Jul 2003

Posts: 1
Problem with mask password.
Hi everyone !

I have problem with getchar function to mask password that will be typed by
user.
How can I mask password leaving cursor just waiting `` caracter (like
Unix/Linux mode). Because with the function that I wrote appear the letter what
I typed. My function don`t mask my own password. My function appear my own
password on screen.

I am using gcc compiler ( I don`t know what version, because is integrated with
another toolkit).
I could use getch() function, but I don`t have CONIO.H library, because I am
compiling with GCC.

Somebody can help me with this problem ?! How can I use getchar function to
work correct mode ?

Here is the code (putting `*` instead the real password):

char *getPassword(char *prompt)
{
char buffer[128]; /* where will be stored the real password */
int i=0;
int letter;

printf(prompt);

while ((i < 127) && (letter != ` `))
{
letter = getchar();


/*_bios_keybrd */
if (letter == BACKSPACE)
{
if (i > 0)
{
buffer[--i] = NULL; /* Delete previews pointer `*` */
putchar(BACKSPACE);
putchar(` `);
putchar(BACKSPACE);
}
else
putchar(7); /* Warning sound */
}
else if (letter != ` `)
{
buffer[i++] = letter;
putchar(`*`); /* Change the real password by `*` */
}
if (letter = ``)
break;
}
buffer[i] = NULL;


return buffer;

}

[]`s Murilo

` ` `
( O O )
+----------------oOO--(_)--OOo---------------------+
|"Learn from yesterday, live for today, hope for |
| tomorrow. The important thing is to not stop |
| questioning" --Albert Einstein |
| |
|"Choice. The problem is choice" --Neo(The Matrix) |
+--------------------------------------------------+
Reply with quote
Send private message
View user's profile Post To page top
shantanu_k06 Posted: Tue Jul 29, 2003 11:23 pm


Joined: 19 Jul 2003

Posts: 29
Problem with mask password.
Hi Murilo,

If you are using GCC under GNU/Linux, there`s always a
package library called N-CURSES (short for "New
Curses"). It has getch() function just the way you
have it in conio.h in TC++3.0/DOS. Run "man curses"
from terminal if you need help. If you don`t have the
package already, get the source and compile it.

The header file for N-CURSES is curses.h so include it
and work the same way you wanted to do with conio.h.

Hope that helps.

Regards,
Shantanu

--- Murilo Regis da Costa <mcosta@...> wrote:
> Hi everyone !
>
> I have problem with getchar function to mask
> password that will be typed by user.
> How can I mask password leaving cursor just waiting
> `` caracter (like Unix/Linux mode). Because with
> the function that I wrote appear the letter what I
> typed. My function don`t mask my own password. My
> function appear my own password on screen.
>
> I am using gcc compiler ( I don`t know what
> version, because is integrated with another
> toolkit).
> I could use getch() function, but I don`t have
> CONIO.H library, because I am compiling with GCC.
>
> Somebody can help me with this problem ?! How can I
> use getchar function to work correct mode ?
>
> Here is the code (putting `*` instead the real
> password):
>
> char *getPassword(char *prompt)
> {
> char buffer[128]; /* where will be stored the
> real password */
> int i=0;
> int letter;
>
> printf(prompt);
>
> while ((i < 127) && (letter != ` `))
> {
> letter = getchar();
>
>
> /*_bios_keybrd */
> if (letter == BACKSPACE)
> {
> if (i > 0)
> {
> buffer[--i] = NULL; /* Delete previews
> pointer `*` */
> putchar(BACKSPACE);
> putchar(` `);
> putchar(BACKSPACE);
> }
> else
> putchar(7); /* Warning sound */
> }
> else if (letter != ` `)
> {
> buffer[i++] = letter;
> putchar(`*`); /* Change the real
> password by `*` */
> }
> if (letter = ``)
> break;
> }
> buffer[i] = NULL;
>
>
> return buffer;
>
> }
>
> []`s Murilo
>
> ` ` `
> ( O O )
> +----------------oOO--(_)--OOo---------------------+
> |"Learn from yesterday, live for today, hope for |
> | tomorrow. The important thing is to not stop |
> | questioning" --Albert Einstein |
> | |
> |"Choice. The problem is choice" --Neo(The Matrix) |
> +--------------------------------------------------+
>
>
> ------------------------ Yahoo! Groups Sponsor
>
> Keep posting
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help