开发者

how to show password in asterik format when we generate random password

开发者 https://www.devze.com 2023-01-17 00:42 出处:网络
i am generate random password and show it i开发者_JAVA技巧n 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 s

i am generate random password and show it i开发者_JAVA技巧n 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.


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.


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


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?


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.


If you want to use Vb.net you will have to use the following code for creating textbox as password

textbox1.passwordchar="*"

If you want to use C Sharp you will have to use the following code for creating textbox as password

textbox1.passwordchar='*';

If you want to use C++ you will have to use the following code for creating textbox as password

textbox->passwordchar='*';
0

精彩评论

暂无评论...
验证码 换一张
取 消