-3

I have a string called password which my user can define with whatever, kim123 is an example.

So later in the code I want to say something like: "You have entered (password but using asterisks) as your password."

If you are still unclear by what I mean, I basically want to turn the password he/she chose into stars:

password = hey123

"You have entered ****** as your password"
dbc
  • 80,875
  • 15
  • 141
  • 235
  • You don't say what UI Framework you are using. If you are using [tag:winforms], are you looking for [How to set a text box for inputing password in winforms?](https://stackoverflow.com/q/2555984) If [tag:wpf] then maybe [How can I make a TextBox be a “password box” and display stars when using MVVM?](https://stackoverflow.com/q/1119605)? But you should never, ever **save** an unhashed copy of a user's password, see e.g. [How to securely save username/password (local)?](https://stackoverflow.com/q/12657792) or [C# - Securely storing a password locally](https://stackoverflow.com/q/16957492). – dbc May 19 '18 at 21:24
  • 4
    If you are using asterisks to be more secure, displaying an accurate length of what the password is goes against that. – docmanhattan May 19 '18 at 21:26
  • You forgot to ask a question! – random May 19 '18 at 22:15
  • I'm using C#, I missed that one. – Jackson Mac Dislike May 19 '18 at 22:39

1 Answers1

2

Then you generate so like

string pass = new String('*', password.Length); //will generate * as big as length of pasword
Console.WriteLine("You have entered {0} as your password", pass);
Rahul
  • 71,392
  • 13
  • 57
  • 105