Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
how do i show password value when editing user details in MVC

I am working on a MVC core project. I have a view on which user can edit user details. I have a input field of type password. When we are creating the user, it works fine in hiding the characters as one type in the textbox, but when I want to edit the user details, the password input does not show a value.

How do I enable an input of type password to show or have a value when editing and at the same time I want to include the show and hide password functionality on the input.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

$(document).ready(function() {
        let model = @Html.Raw(Json.Serialize(Model));

        let passwordEl = $("#Password");
        let showHide = $('#showHidePassword');
        let showHideSpan = $('.icon');

        if (model.InstitutionModel.InstitutionSMTP.Id == 0) {
            passwordEl.attr('type', 'password');
        } else if (model.InstitutionModel.InstitutionSMTP.Id > 0) {
            passwordEl.attr('type', 'password');
        }

        showHide.click(function (e) {
            let type = passwordEl.attr('type') === 'password' ? 'text' : 'password';
            passwordEl.attr('type', type);
            if (showHideSpan.hasClass('fa fa-eye')) {
                showHideSpan.removeClass('fa fa-eye').addClass('fa fa-eye-slash');
            } else {
                showHideSpan.removeClass('fa fa-eye-slash').addClass('fa fa-eye')
            }
        })
    })
 <div class="form-group row ">
                    <label class="col-sm-3 col-form-label control-label" for="accountHolder">Password</label>
                    <div class="col-sm-9 input-group required_field">
                        <input asp-for="Password" id="Password" class="form-control border border-secondary" type="text" />
                        <div class="input-group-append">
                            <button class="btn btn-primary" type="button" id="showHidePassword" style="height:38px;">
                                <span class="fa fa-eye icon"></span>
                            </button>
                        </div>


                        <span asp-validation-for="Password" class="text-danger"></span>
                    </div>
                </div>

`

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use a button to change the type of the input,here is a demo:

html:

<input type="password" id="passwd" name="passwd">
<button type="button" id="eye" onclick="ShowPassword()">
    <img src="https://cdn0.iconfinder.com/data/icons/feather/96/eye-16.png" alt="eye" />
</button>

js:

function ShowPassword() {
            var s = document.getElementById("passwd");
            s.type = s.type == "password" ? "text" : "password";

        }

result:

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar

0

Although, it is not recommended to directly show the user's password, instead you should ask user to enter old password and also have fields for new password.

In order to show value of input password field, you can set type attribute of input field to text.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda