C
C#•5mo ago
Rafcord

Button showing password.

I want to add button that shows password. How can I do that? This is my code:
string encryptedPassword = "";

for (int i = 0; i < Model.Password.Length; i++)
{
encryptedPassword += "*";
}

<p ALIGN="LEFT"><b>Id:</b> @Model.Id </p>
<p ALIGN="LEFT"><b>Rank: </b> @Model.Ranks</p>
<p ALIGN="LEFT"><b>Nick: </b> @Model.Nick</p>
<p ALIGN="LEFT"><b>Email:</b> @Model.Login. </p>
<p ALIGN="LEFT"><b>Password:</b> @encryptedPassword </p>
<button ALIGN="LEFT" type="button">Show password</button>
string encryptedPassword = "";

for (int i = 0; i < Model.Password.Length; i++)
{
encryptedPassword += "*";
}

<p ALIGN="LEFT"><b>Id:</b> @Model.Id </p>
<p ALIGN="LEFT"><b>Rank: </b> @Model.Ranks</p>
<p ALIGN="LEFT"><b>Nick: </b> @Model.Nick</p>
<p ALIGN="LEFT"><b>Email:</b> @Model.Login. </p>
<p ALIGN="LEFT"><b>Password:</b> @encryptedPassword </p>
<button ALIGN="LEFT" type="button">Show password</button>
9 Replies
Hazel 🌊💃
Is this Blazor?
Murten
Murten•5mo ago
Looks like it.
Rafcord
Rafcord•5mo ago
I don't know what blasor is. This is in cshtml file.
Hazel 🌊💃
The simple answer is to toggle between displaying encryptedPassword and Model.Password. It's simple enough to add a bool which is toggled on button click.
Rafcord
Rafcord•5mo ago
This is my idea, but I don't know how to toggle after pressing the button.
string encryptedPassword = "";
bool isPasswordShown = false;

for (int i = 0; i < Model.Password.Length; i++)
{
encryptedPassword += "*";
}

<p ALIGN="LEFT"><b>Id:</b> @Model.Id </p>
<p ALIGN="LEFT"><b>Rank: </b> @Model.Ranks</p>
<p ALIGN="LEFT"><b>Nick: </b> @Model.Nick</p>
<p ALIGN="LEFT"><b>Email:</b> @Model.Login. </p>

if (isPasswordShown)
{
<p ALIGN="LEFT"><b>Password:</b> @Model.Password </p>
}
else
{
<p ALIGN="LEFT"><b>Password:</b> @encryptedPassword </p>
}

<div align="left">
<input type="button" id="0" value="Show password" style="border-radius: 7px;background-color: #E9987D; color: white;" onclick="!isPasswordShown " />
</div>
string encryptedPassword = "";
bool isPasswordShown = false;

for (int i = 0; i < Model.Password.Length; i++)
{
encryptedPassword += "*";
}

<p ALIGN="LEFT"><b>Id:</b> @Model.Id </p>
<p ALIGN="LEFT"><b>Rank: </b> @Model.Ranks</p>
<p ALIGN="LEFT"><b>Nick: </b> @Model.Nick</p>
<p ALIGN="LEFT"><b>Email:</b> @Model.Login. </p>

if (isPasswordShown)
{
<p ALIGN="LEFT"><b>Password:</b> @Model.Password </p>
}
else
{
<p ALIGN="LEFT"><b>Password:</b> @encryptedPassword </p>
}

<div align="left">
<input type="button" id="0" value="Show password" style="border-radius: 7px;background-color: #E9987D; color: white;" onclick="!isPasswordShown " />
</div>
Hazel 🌊💃
You're not updating isPasswordShown to its negated value. You have to assign the result of that negation. I'd start with that.
Rafcord
Rafcord•5mo ago
This code doesn't work. So what should it look like?
string encryptedPassword = "";
bool isPasswordShown = false;

for (int i = 0; i < Model.Password.Length; i++)
{
encryptedPassword += "*";
}

<p ALIGN="LEFT"><b>Id:</b> @Model.Id </p>
<p ALIGN="LEFT"><b>Rank: </b> @Model.Ranks</p>
<p ALIGN="LEFT"><b>Nick: </b> @Model.Nick</p>
<p ALIGN="LEFT"><b>Email:</b> @Model.Login. </p>

if (isPasswordShown)
{
<p ALIGN="LEFT"><b>Password:</b> @Model.Password </p>
}
else
{
<p ALIGN="LEFT"><b>Password:</b> @encryptedPassword </p>
}

<div align="left">
<input type="button" id="0" value="Show password" style="border-radius: 7px;background-color: #E9987D; color: white;" onclick="isPasswordShown = !isPasswordShown " />
</div>
string encryptedPassword = "";
bool isPasswordShown = false;

for (int i = 0; i < Model.Password.Length; i++)
{
encryptedPassword += "*";
}

<p ALIGN="LEFT"><b>Id:</b> @Model.Id </p>
<p ALIGN="LEFT"><b>Rank: </b> @Model.Ranks</p>
<p ALIGN="LEFT"><b>Nick: </b> @Model.Nick</p>
<p ALIGN="LEFT"><b>Email:</b> @Model.Login. </p>

if (isPasswordShown)
{
<p ALIGN="LEFT"><b>Password:</b> @Model.Password </p>
}
else
{
<p ALIGN="LEFT"><b>Password:</b> @encryptedPassword </p>
}

<div align="left">
<input type="button" id="0" value="Show password" style="border-radius: 7px;background-color: #E9987D; color: white;" onclick="isPasswordShown = !isPasswordShown " />
</div>
Hazel 🌊💃
How to assign a value to a variable on button click in razor pages (or cshtml if you're not sure on tech).
I don't deal with razor/blazor enough to know for sure without researching it myself.
Pobiega
Pobiega•5mo ago
if this is razor, it won't do anything, since razor isn't reactive
Want results from more Discord servers?
Add your server
More Posts
Convert to wave file gives COMExceptionHello! I have rest API using ASP.NET Core app .net 7 and I'm trying to convert a WebM file into a waconfused, passing tuple?```cs // fixes times like more than 60 seconds // int, int, int public (intUWP Digest credentials not supported?i have the following code in my xamarin.forms project. (yeah i know its deprecated, but thats what iHow can I convert null entries in JSON data to a default value?I have JSON data that contains null entries for some values. It would make the business code a lot eHow do I take text from input element of a form and put it in AspNetUsers table properly?I'm passing it from view to controller action through parameters, if that's relevant. This input eleWindows keyboard hook (SetWindowsHookExA) doesn't get called.Simplified version: ```cs KeyboardListener.KeyPress += (key) => { Console.WriteLine(Enum.GetName✅ What's a good strategy to load serverside resources into your controller?Right now I have a few images and videos that so far i've been loading to views using Directory callhow can i get the data from database and put them to a dropdownhow can i get the data from database and put them to a dropdown , when im trying to do that it showsDont know what i did, program now giving CS0101 and CS0111 errors.Cant launch the debug thingamabob. How would I fix it?✅ Changed something manually in AspNetUsers and now can't loginI went in with SQL Server Object Explorer and manually changed the NormalizedUserName column and now