Thread: Password field with: **********

  1. #46
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Why not use PDCurses as Noir suggested then, at least its slightly portable.

  2. #47
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by quzah View Post
    I didn't miss anything. I answered him first. Nearly all of my other posts were directed to you.
    And God himself is still wondering "Why?"

    I didn't tell him it wasn't portable. I told you that your code wasn't portable. But even if I did tell him that, it would have been regarding my first post, and it is important to know that, because they didn't mention their compiler or operating system in the first post. As such, since there is no portable way to do that, I would have still been in the right telling them that it's not portable. Because without knowing their platform, there's no way to tell them how to do it.
    Great, we'll get a sing along of yet another verse of "Gloom, Despair, and no port-a-bility!"

    That will REALLY help get a function coded!

    I'm not a damn bit surprised you didn't catch it though, because you've proven yourself a bit on the slow side.
    Yet leaving you in the dust - amazing. I cheat, and listen to the OP, and not to the no-bird chorus.

    You're just mad that it took you six posts to realize that \r and \n aren't the same thing. So you're being intentionally stubborn insisting that your way, putting the number 8 is better than putting '\b'.
    I never said that, never inferred that, and stated exactly why I did it 2 or 3 times now. It's just easier for me to work with ASCII values than to work with escape char's. I have experience with coding ASCII values from years ago. I haven't done much coding with escape char's.

    Indio now has a basic password function he can polish up to his wants and needs.

    Why do I have to keep repeating the same info, over and over? Read my posts and quit stating obvious misstatements of what I posted.

    Adak

  3. #48
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by laserlight View Post
    I can see where you are coming from, and indeed in this case there is no portable way of doing the job, so the use of getch() is fine, as long as it is noted to be nonportable. On the other hand, seeking on stdin can be avoided with alternatives that are both portable and compliant with the standard, so you should recommend such an alternative instead.
    That's not true, and I challenge you to find concise, clear, and portable code that will pause that program, for ONE (and only one), enter key to be hit. REGARDLESS of the state of the keyboard buffer. Yes, I'm talking about an extra 20 char's being keyboarded after the password array is full (and not accepting any more input).

    I tried three - and none worked right for both a full keyboard buffer, and an empty keyboard buffer.

    Newer compiler's may have something that will do this better than the old Borland I was using, but you give me the code, and I'll try it on my compiler (or you can also try it). But it has to work on Borland or Turbo C compilers, prior to version 2.

    Adak

  4. #49
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    http://pdcurses.sourceforge.net/ more portable than your suggestion.

  5. #50
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Adak View Post
    That's not true, and I challenge you to find concise, clear, and portable code that will pause that program, for ONE (and only one), enter key to be hit. REGARDLESS of the state of the keyboard buffer. Yes, I'm talking about an extra 20 char's being keyboarded after the password array is full (and not accepting any more input).
    Code:
    char buf[ 21 ] = {0};
    fgets( buf, sizeof buf, stdin );
    fgets says "Hi".

    Line buffered, one, and only one, enter at a time. Just like you wanted, reading a limited number of characters at once. Now naturally you'll have some stupid ass argument that makes no sense to anyone here, something like "I wanted a portable password box that wouldn't allow any more than that amount of characters! See, I can type 4000 there!" -- But before you do, that's not what you said you wanted. You said you wanted a function that read up to a newline, and disregarded everything past a set amount. Well, there you go. Now after you've hit enter, clear your buffer on your own if the last element in your array isn't a newline. Problem solved.

    No, this isn't going to mask your password, but that's not what you said you wanted for this question.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #51
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by quzah View Post
    Code:
    char buf[ 21 ] = {0};
    fgets( buf, sizeof buf, stdin );
    fgets says "Hi".

    Line buffered, one, and only one, enter at a time. Just like you wanted, reading a limited number of characters at once. Now naturally you'll have some stupid ass argument that makes no sense to anyone here, something like "I wanted a portable password box that wouldn't allow any more than that amount of characters! See, I can type 4000 there!" -- But before you do, that's not what you said you wanted. You said you wanted a function that read up to a newline, and disregarded everything past a set amount. Well, there you go. Now after you've hit enter, clear your buffer on your own if the last element in your array isn't a newline. Problem solved.

    No, this isn't going to mask your password, but that's not what you said you wanted for this question.


    Quzah.
    You've misunderstood my post to laserlight.

    I was asking about a line or two of code, to just pause the program and await ONE enter key hit, regardless of the state of the keyboard buffer. Something clear, concise, and portable.
    (Not System("pause"), obviously). Has to work on Borland/Turbo Compilers prior to ver. 2.

    This has NOTHING to do with the password being displayed, etc. That's all done now.

    Until you can show some respect, I really don't care what code you propose.

  7. #52
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This has already been covered. There is no portable way to read a keystroke, which is what you're asking. If you handle your input correctly, you don't need to worry about it, because there's no need for one.

    As to respect, I don't respect you, so don't hold your breath.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #53
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by laserlight View Post
    I can see where you are coming from, and indeed in this case there is no portable way of doing the job, so the use of getch() is fine, as long as it is noted to be nonportable.
    The definition of "portable" I use in my daily work is somewhat different. In essence, a codebase is "portable" if it can be reasonably altered to run on an arbitrary platform. "Reasonable" is a subjective term, but one which you can get a good feel for with experience. As others pointed out here, there is simply no way to do certain things "portably" in the sense that the exact same code works everywhere. For instance, clearing the screen. But a program which clears the screen on many different platforms can be written.

    Portability, like encapsulation, is a quantifiable spectrum, not a binary concept. A better term for the latter idea might be "adherence to the standard." A program might be extremely portable in that it can easily be made to run on any given system, or it might be horrendously unportable in the sense that its system-dependent features are grossly intertwined with its system-independent features. This is just a symptom of bad design.

  9. #54
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Very nicely worded.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #55
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    As others pointed out here, there is simply no way to do certain things "portably" in the sense that the exact same code works everywhere.
    ...
    A program might be extremely portable in that it can easily be made to run on any given system, or it might be horrendously unportable in the sense that its system-dependent features are grossly intertwined with its system-independent features. This is just a symptom of bad design.
    I agree.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #56
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    I'm drunk and this thread makes me laugh.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  2. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Password Field
    By Explicit in forum C Programming
    Replies: 10
    Last Post: 05-22-2004, 08:22 PM
  5. password field
    By trekker in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 09-27-2003, 01:56 AM