CrazyEngineers
  • Password : C - Programming

    dinky

    Member

    Updated: Oct 15, 2024
    Views: 3.5K
    anyone know then plz help me....I want to create password in c programming
    user input will be int or char type and output should be in form of string like ******.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Harish Kotra

    MemberSep 7, 2012

    Well, so you take the input as password should be either in numbers of in characters right ? If that's the case,
    just use the rand() function to generate what you need.
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberSep 7, 2012

    Your question looks like password display problem rather than password creation..i guess..
    So for display the simplest way is to take input using getch() along with a single printf("*"); statement inside a loop until user does not press enter.
    PS: Some programmers would not recommend this because <conio.h> is not a standard headerfile. But for this case this is a valid solution.😀😁
    Are you sure? This action cannot be undone.
    Cancel
  • Vishal Sharma

    MemberSep 8, 2012

    rahul69
    Your question looks like password display problem rather than password creation..i guess..
    So for display the simplest way is to take input using getch() along with a single printf("*"); statement inside a loop until user does not press enter.
    PS: Some programmers would not recommend this because <conio.h> is not a standard headerfile. But for this case this is a valid solution.😀😁
    It's not that, some programs don't support getch() It's the programming environment which doesn't support this header as it is not the standard given by ANSI.

    You are right about printing the * but don't use printf() for that
    printf is very expensive way to print just one character!
    the reason for that are:
    1> gets the format string
    2> parse and analyze the string
    3> find out that there's a CHAR format specifier
    4> call the char output subfunction
    5> gets the character parameter
    6> output the character to the screen

    So, the above things just to print a character, is a bad idea.. Use putchar('*');
    😀

    anyone know then plz help me....I want to create password in c programming
    user input will be int or char type and output should be in form of string like ******.
    Algorithm for this part is something like this

    1) z = 0
    2) run the loop

    while( (c = getchar()) != 13)
     
        {
     
            password [z++] = c;
     
            putchar('*');
     
          }
    3) after loop
    password[z++] = '\0';


    #-Link-Snipped-#

    This is not completed yet!! what if the user enters a wrong password?? Think about it 😀 try to use backspace. Try fixing the problem! If you don't get it, post again.. 😀
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register