Click here to Skip to main content
Licence CPOL
First Posted 30 Jun 2008
Views 35,076
Downloads 347
Bookmarked 28 times

Silverlight Password Box

By Maciej Gren | 30 Jun 2008
A small article about how to create a simple password text box in Silverlight 2 Beta 2
1 vote, 11.1%
1
1 vote, 11.1%
2
2 votes, 22.2%
3
1 vote, 11.1%
4
4 votes, 44.4%
5
3.50/5 - 9 votes
μ 3.50, σa 2.63 [?]
PasswordBox

Introduction

While digging into Silverlight 2 Beta 2, I have noticed that there is no Password Box available. It will be in the final version, but till then we have to figure out some other way to do it. This solution is quick and maybe even a little bit dirty but it works and that's what makes it valuable enough to be posted. :)

Using the Code

Just attach the tbPassword_TextChanged method (from the attached example) to your password text box (simple Silverlight Text Box).

string _currentText = "";
void tbPassword_TextChanged(object sender, TextChangedEventArgs e)
{
    TextBox __textBox = sender as TextBox;
    if (__textBox != null)
    {
        string __currentText = __textBox.Text;
        if (__currentText.Length < _currentText.Length)
            _currentText = _currentText.Substring(0, __currentText.Length);
        if (__currentText != "")
        {
            for (int i = 0; i < __currentText.Length; i++)
            {
                if (__currentText[i] != '\u25CF')
                {           
                    string __temp = __currentText.Remove(i, 1);
                    __textBox.Text = __temp.Insert(i, "\u25CF");
                    _currentText = _currentText.Insert
			(_currentText.Length, __currentText[i].ToString());
                }
            }
        }
    }
}

In the _currentText, you will find text from the password box.

Points of Interest

I am working on quite a big RIA Silverlight application. Lacking this basic password box made my stomach ache. Hopefully, in the final release of Silverlight, we won't have such issues anymore.

History

While creating this small sample, I was inspired by Michael Sync's post. Unfortunately, Silverlight 2 beta 2 sample source code did not work properly and that is why I decided to write a simpler solution (IMHO).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Maciej Gren

Team Leader
GOYELLO
Poland Poland

Member
I started work with .Net in year 2005. During my studies I was a team leader of project which scored 4th place on Polish Imagine Cup Finals where we delivered WPF application with https WCF services. Meanwhile I have worked on Windows Mobile Applications with Windows CE 5.0. I have learned how to create Windows CE Images using Platform Builder and I gained high skills in Compact Framework 2.0. After one year of developing using this framework I have switched to ASP.Net. Currently I am using Monorail Framework together with Active Record and Extjs library (for presentation layer). I am a Team Leader in GOYELLO where we delivered quite successful projects. My aim is to develop good quality applications but not forgetting about reality. Always there are some drawbacks on each solution. The case is to find the proper balance Smile | :)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Question[My vote of 2] What about the cursor???? PinmemberSike Mullivan8:02 27 May '10  
GeneralPasswordBox Control PinmemberJinal Desai - LIVE1:36 10 May '10  
GeneralSome changes for given code [modified] Pinmemberintrosas8:24 19 Sep '08  
QuestionConnection with the server? Pinmembersydaze4:23 10 Sep '08  
Hi, there's something I still don't understand with silverlight:
When I created this login box, what are the solutions to send the data (login/password) to the servers and receive an answer to know if it's correct or not.
I read about web services but is it the only solution for silverlight to communicate with the server?
GeneralWorks just fine, just add "__textBox.Select(__textBox.Text.Length, 1);" to the end ... Pinmemberericsson00715:16 22 Aug '08  
GeneralIl y a beaucoup plus simple Pinmembermandark.dev11:04 14 Aug '08  
QuestionSilverlight can use build-in html control? PinmemberJcmorin4:55 1 Jul '08  
AnswerRe: Silverlight can use build-in html control? PinmemberMaciej Gren11:35 1 Jul '08  
Generalvalidating User Name & Password Pinmember248912821:03 30 Jun '08  
GeneralRe: validating User Name & Password PinmemberMaciej Gren8:34 1 Jul '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 30 Jun 2008
Article Copyright 2008 by Maciej Gren
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid