tags:

views:

124

answers:

5

i am generate random password and show it in a textbox. when i am set textbox property textmode to password then it doesn't show in textbox but when i set it singleline then password shows in textbox. I am using following code --

textbox1.attributes.add("value",passwordvalue);

for show i am using --

textbox1.text = textbox1.attributes["value"].tostring();

Same happing with when i edit record. password doesn't show in textbox.

+1  A: 
textbox1.text = "yourrandompassword"

i dont get what you are trying to do with the attributes. Are you using a asp control element for the textbox? if you are generating a random password, i guess you want to show it to your user, not hide is with the asterix'es?

Stefanvds
+3  A: 

When you set a textbox in password mode, it renders as an <input type="password" >, which hides what's written in it, but this also forbids setting the value of the field. A password field is strictly for users to type in, you can't pre-fill it with anything.

If you want a textbox that hides the characters, but still allows setting the initial value, you have to build it yourself (or find something that someone else built) using HTML and client script.

Guffa
Having a starting value is as simple as `<input type="password" value="initial_value" />`. No script required.
Jeriko
A: 

Maybe you can use HiddenValues or ViewStates to store the password, and set value of TextBox just basic asterisk like "**".

When you want to do something with generated password use HiddenValue or ViewState.

barmenseriff
+2  A: 

Does this help?

HTML

<body>
  <input type="text" id="passbox" />
  <input type="submit" onclick="generate_password()" value="Generate Password" />
  <input type="submit" onclick="toggle_passbox()" value="Toggle Box" />
</body>

JAVASCRIPT

function passbox() {
  return document.getElementById('passbox');
}

function generate_password() {
   passbox().value=Math.random().toString(16).slice(2);
}

function toggle_passbox() {
  passbox().type= passbox().type == "password" ? "text" : "password";
}

You can test this at http://jsbin.com/uxano3

Jeriko
@Jeriko: Good one really!
Kangkan
That in the OP scenario + if javascript is disabled/blocked, it'll make either a non masked password field or the same as the OP had.
eglasius
The starting state can be reversed, javascript degradation isn't really necessary - if thats what you mean?
Jeriko
A: 

That approach doesn't make sense since even if it showed it would be just *, and then that leaves the user in the same situation. The password field just isn't meant to be showed.

If you must keep with the generate random password, you could:

  • Show some simple text above the password field, something like: "Please enter your password in the field below. Alternatively leave it blank, and use this password we have generated for you: SomeNicePassword"

About the edit scenario, you shouldn't have passwords in clear, its just not safe and could upset some customers. Besides, an edit password feature usually requires the user to enter their current password and the new one in separate fields, to make sure it wasn't that it wasn't that the user left the session open and someone else is trying to take over the account.

eglasius