Silverlight – Password field no longer missing

EDIT : There’s now a real PasswordField, our tricks is no longer needed, just read :
http://silverlight.net/blogs/msnow/archive/2008/09/29/silverlight-tip-of-the-day-47-how-to-implement-a-password-box.aspx

Everybody developping in Silverlight knows that there’s no password textbox, and some of us rewrite a UserControl to replace it… yeark !!
There’s a so simple way to create a password textbox :
Use a TextBox and change the font with a home made font in which all characters are ‘*’ …
0 lines of code, do it in XAML

<TextBox FontFamily="password.ttf#Password"/>

FontFamily can download a file and pick a font from this file, the syntaxe is given “file.ttf#fontname” in my password.ttf the font name is “Password”, with the .ttf have to be in your ClientBin (relatives or absolute URI can be used with nothing, the root directory is checked, so put it in your ClientBin)
According to TimHeuer’s comment, after beta 2, embedding fonts will not work with this way, so watch his video Using custom fonts in silverlight to do it with the right way :)

Dont want to create a .ttf ? download mine. password.ttf

This entry was posted in silverlight and tagged , . Bookmark the permalink.

14 Responses to Silverlight – Password field no longer missing

  1. Marc Roussel says:

    OH and for dummy like me. What do I do with your .ttf
    Windows Vista Home Premium

    Thank you

  2. Palard Julien says:

    Just put it in your ClientBin folder.

  3. timheuer says:

    Palard, what a great little trick! One thing to note that post beta 2, embedding fonts will have to follow a supported pattern. See http://silverlight.net/learn/learnvideo.aspx?video=69800 for the supported method.

  4. Anna says:

    Wow, awesome idea! Thanks for sharing!

  5. Awesome idea! very creative thinking.

    keep up the great job.

  6. Prasad says:

    Hi,

    looking cool solution man………….
    but need to ask one thing can i use this font in my application without any issue….
    Is that font file is open to used by anybody?
    or any issue about copyright there………

    Thanx in advance….

  7. Palard Julien says:

    Prasad : Thanks :) It’s a font I made, so you can reuse it whithout any restrictions, it’s free :)

  8. Hi,

    You solution seems to be cool, but only seems… :)
    In fact, because you are using a custom font, the content of the textbox isn’t masked and you can get its content with a simple copy/paste, which isn’t very secure.
    By the way, I think that writing a new TextBox with different input mode is really much sexy and secure.

  9. Palard Julien says:

    To : Adrien Siffermann
    Hi,

    I agree, but, if you are writting your password it means you know it. Then I guess you won’t steal your own password by copying/pasting it.
    In my opinion masking with stars is only a security for curious guys who might see your screen…

  10. Stasys says:

    There is some problem with other charset like cyrilic, baltic etc.

  11. Gongdo says:

    Wow! Awesomely simple!
    However There are some problems.
    – You can copy&paste it! :D
    – Not works in non-English languages such as Korean, Japanese, Chinese…
    (TextBox will show there characters.)

    Although this simple solution has 2 problems, you can find way like :
    – You can prevent copy&paste to use follow code in TextBox’s KeyDown event handler.
    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
    (sender as TextBox).Select(0, 0);)
    – You can make password.ttf to support your language’s characters.
    (but it may not regconize upper/lower case.)

  12. First of all congratulation for such a great site. I learned a lot reading article here today. I will make sure i visit this site once a day so i can learn more.

  13. Peter says:

    The download link is broken would be nice if you could fix that!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>