Thread: How to hide password

  1. #1
    Unregistered
    Guest

    Question How to hide password

    Hello!

    I'm begginer to MFC so don't mind if I ask stupid question.
    This is my problem:
    I'm writting this program where you have to write password into a dialog resources before you go to next level of program.
    Is anybody know how to hide password t ex **** should be showed when you fil in password.

    Is there a way to do this????

    Thanks
    confused begginer

  2. #2
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Anythings possible lol, its pretty simple to make an edit contol have password view thingi. I do not know much MFC but in the API when you create your edit box, you add ES_PASSWORD style, dunno if you use this in MFC though, also if your using a dialog right click on ur edit box, and go to properties and tick the password style.

    Hope that helps,
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  3. #3
    Unregistered
    Guest
    Hi!
    Thanks! It helped

    Best Regards

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    password char

    I just had to try it thanks.... This worked for me.

    void PasswordDlg ::OnInit()
    {
    m_edtPassword.SetPasswordChar( TCHAR( '*' ) );
    }



    void PassworDlg::OnButtonViewPassword()
    {
    char buffer[255]={0};
    CString str;

    m_edtPassword.GetLine(0, buffer, 8);

    str = buffer;


    MessageBox( str );
    }
    zMan

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    If you want to get low-level with putting the '*' in the edit box instead of the char, you can intercept the EN_CHANGE (I believe this is the message before the edit puts the char into the edit box and EN_UPDATE is after it is put in) and append the char onto a string and then just put in a '*' into the edit box. Although, I'm not sure, even if you intercept this message, that it won't put the normal char in anyway. For instance, if you use this logic, you might get output like T*e*s*t*...so you just use ES_PASSWORD as the style of window.

    My $0.02

    Garfield
    1978 Silver Anniversary Corvette

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    EN_CHANGE to change the char to *

    I did it that way the last time and it was more trouble than it was worth... because I had a hardtime position the caret in the proper location...

    also the call is recursive because SetWindowText(...) will also send another EN_CHANGE....
    it is somewhat of a bad dream to do it that way....
    zMan

  7. #7
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    234
    Bring uo your proerties for the edit box in your resource pane. Select the styles tab, or the similiar, and select the password characteristic.

  8. #8
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Re: EN_CHANGE to change the char to *

    Originally posted by zMan
    I did it that way the last time and it was more trouble than it was worth... because I had a hardtime position the caret in the proper location...

    also the call is recursive because SetWindowText(...) will also send another EN_CHANGE....
    it is somewhat of a bad dream to do it that way....
    Yes, that makes sense. You should've done tested the ascii value to see if it was "*" first and if it was then that would end the recursion (because after the change it would override that option, Understand?). So, that would work out. But, you are right, just use ES_PASSWORD style. It would be easy if we were designing the control from the start to enable this and it would make it simple. So, don't think it's a short-cut, just use that constant...

    Garfield
    1978 Silver Anniversary Corvette

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. Enter password, hide by "*".
    By toysoldier in forum C++ Programming
    Replies: 28
    Last Post: 08-15-2004, 08:13 AM
  3. Hide Password On Unix
    By Moepi in forum C Programming
    Replies: 3
    Last Post: 05-24-2002, 07:33 AM
  4. Hide Password Characters
    By Moepi in forum C++ Programming
    Replies: 2
    Last Post: 05-24-2002, 04:57 AM
  5. Hide Password Chars
    By Moepi in forum C Programming
    Replies: 4
    Last Post: 05-24-2002, 03:29 AM