Hi, Setting the text property for a textbox with textmode=single and multiline is pretty straight forward by giving TextBox1.Text = "The text we want to set"; However, if we set the Textmode property to Password, then we cannot simply set the text using the
TextBox.text. In practical scenarios, we may not want to set the password for obvious reasons that password is one which we retrieve from the user and it shoult not be set. Also, even if we set some password, the user cannot read it as it is just a sequence
of dots. If, for however, due to specific reasons, we need to set the password, then we can do the same by using the following code:-
txtpasswd.Attributes.Add("value", "the password we wish to set");
Or, if you are assigning the password from the database you can use a DataReader in place of the actual password, as follows :
Hey everyone, I am not sure if everyone knows this, and it is not mentioned in the post above, but if you use the attributes.Add() method to add the password value, your password will be visible in the Source of the page. This was a major problem for us and
in my view a huge security risk...and I just wanted to let people know as I almost continued with the above solution. Thanks Jase
The method shown above should work given the right security planning.
This is one way to do it using non-symmetric encryption. For security reasons you should Encrypt your passwords and stored them encrypted.
When you are ready to authenticate an user, encrypt their input and compare it to the encrypted password stored in the database.
It is worth noting that you can do other things like add scripts to - supported - events in HTML 4.0 elements. (i.e. myButton.Attributes.Add("OnClick","JavaScript:alert('hi you doing?!');")
In non-practical scenarios - such as automated testing - I have used code like the one shown above. This saves us from having to type the password everytime and allows us to test an application under disparate roles/accounts.
Just because a solution does not fit a practical scenario does not rule it out 100%. [:|]
ranganh
Star
12085 Points
2435 Posts
Microsoft
Assigning the text value for a Password Textbox
Dec 02, 2004 05:43 AM|LINK
txtpasswd.Attributes.Add("value", "the password we wish to set");Or, if you are assigning the password from the database you can use a DataReader in place of the actual password, as follows :txtpasswd.Attributes.Add("value", objRdr["Password"].ToString());Cheers.Harish
http://geekswithblogs.net/ranganh
MikeMinsk
Participant
1885 Points
377 Posts
Re: Assigning the text value for a Password Textbox
Feb 26, 2005 08:00 PM|LINK
ranganh
Star
12085 Points
2435 Posts
Microsoft
Re: Assigning the text value for a Password Textbox
Feb 28, 2005 06:37 AM|LINK
Harish
http://geekswithblogs.net/ranganh
Jorell
Member
425 Points
85 Posts
Re: Assigning the text value for a Password Textbox
Mar 24, 2005 07:08 PM|LINK
azamsharp
All-Star
24614 Points
4612 Posts
Re: Assigning the text value for a Password Textbox
Mar 24, 2005 11:51 PM|LINK
HighOnCoding
longhorn2005
All-Star
22676 Points
1368 Posts
Re: Assigning the text value for a Password Textbox
Mar 25, 2005 10:40 AM|LINK
Proper Preparation Prevents Poor Performance
My Blog
ChicoUser
Participant
830 Points
166 Posts
Re: Assigning the text value for a Password Textbox
Apr 04, 2005 06:05 PM|LINK
This is one way to do it using non-symmetric encryption. For security reasons you should Encrypt your passwords and stored them encrypted.
When you are ready to authenticate an user, encrypt their input and compare it to the encrypted password stored in the database.
It is worth noting that you can do other things like add scripts to - supported - events in HTML 4.0 elements. (i.e. myButton.Attributes.Add("OnClick","JavaScript:alert('hi you doing?!');")
-
Francisco
(A+,MCP,.NET Framework Certified)
ranganh
Star
12085 Points
2435 Posts
Microsoft
Re: Assigning the text value for a Password Textbox
Apr 05, 2005 07:50 AM|LINK
Hi,
Just a footer note...
In practical scenarios, you don't need to display the Password text field at all.
What is that is going to benefit if you just show them as a series of Dots. Obviously you cannot show the actual text.
So, password should always be received as input from the User and not be retrieved and displayed in the Page like other fields.
Thanks.
Harish
http://geekswithblogs.net/ranganh
longhorn2005
All-Star
22676 Points
1368 Posts
Re: Assigning the text value for a Password Textbox
Apr 12, 2005 07:22 AM|LINK
I agree with you 100%
Proper Preparation Prevents Poor Performance
My Blog
ChicoUser
Participant
830 Points
166 Posts
Re: Assigning the text value for a Password Textbox
Apr 12, 2005 03:09 PM|LINK
In non-practical scenarios - such as automated testing - I have used code like the one shown above. This saves us from having to type the password everytime and allows us to test an application under disparate roles/accounts.
Just because a solution does not fit a practical scenario does not rule it out 100%. [:|]
-
Francisco
(A+,MCP,.NET Framework Certified)