Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

encryption in c 2

Status
Not open for further replies.

191289

IS-IT--Management
Aug 3, 2000
2
FI
Hei ! can anybody tell me how password is encrypted into star (*)in c language?. I couldn't find some form of example in normal c books ?
 
Do you want to know how to actually encrypt some data or just how to print *'s to the screen when the user types a password?
 
Thank you Kim for your question.
I want to see the script how you hide the characters and change it into (*) in password routine.
 
If you write the software in an windows environment and C++ it is very easy (PasswordCharacter='*')

If you have a Dos or simple Unix environment you have to do it by your own.
* Turn off echo (ioctl)
* read a character from stdin and
* write the Passwordcharacter to stdout

it is really easy.
 
191289:
Here is one way of doing it....

#include <stdio.h>
#include <conio.h>

int main()
{
int c, counter = 0;
char buffer[32];

do
{
buffer[counter] = c = getch(); /*Use non-ANSI function to get from keyboard without writing to screen*/
putc('*',stdout);
counter++;
}
while ( c != 13 && counter < 31);

buffer[counter] = 0; /*Put a null character at the end of the string!*/
printf(&quot;\npassword is --> %s&quot;, buffer); /*Print out password*/


return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top