Thread: passswords

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    passswords

    how can i get my prog to accpet a text password

    like:
    cin>>passcode;

    would accept a number i want sum text to be accepted
    also what do i use i.e. int, char

  2. #2
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    cin.getline(passcode, 10);

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    317
    plus you would define passcode as a char array, the size of which would depend on how long you wished the max length of the password you wanted. Remember arrays start at 0.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #include <iostream>
    #include <string>
    using std::cout;
    
    #define CORRECT_PASS "enter"
    
    int main ( void )
    {
      std::string password;
      cout<<"Enter your password: ";
      std::getline ( std::cin, password );
      if ( password == CORRECT_PASS )
        cout<<"All is well\n";
      else
        cout<<"Wrong password\n";
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  5. #5
    Unregistered
    Guest
    *gasp

    comparing strings with ==. shame on you.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    um you can...
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >comparing strings with ==. shame on you.
    The C++ string class has an overloaded operator == for comparing two strings. Perhaps you were in a C mindset when you read this.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed