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"/>
Download this code: password.xml
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
August 14th, 2008 at 11:44 pm
OH and for dummy like me. What do I do with your .ttf
Windows Vista Home Premium
Thank you
August 14th, 2008 at 11:48 pm
Just put it in your ClientBin folder.
August 18th, 2008 at 4:00 am
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.
August 18th, 2008 at 9:57 am
Wow, awesome idea! Thanks for sharing!
August 26th, 2008 at 9:16 pm
Awesome idea! very creative thinking.
keep up the great job.
August 28th, 2008 at 8:50 am
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….
August 28th, 2008 at 9:44 am
Prasad : Thanks :) It’s a font I made, so you can reuse it whithout any restrictions, it’s free :)
August 31st, 2008 at 1:18 am
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.
August 31st, 2008 at 1:30 am
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…
September 19th, 2008 at 7:54 pm
There is some problem with other charset like cyrilic, baltic etc.
September 26th, 2008 at 3:12 am
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.)
December 18th, 2008 at 1:56 pm
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.