Password field in C#

Total Post:102

Points:714
 3577  View(s)
Ratings:
Rate this:

I am using entity framework and .net 4.5 with c#5 for first time from last 2-3 days and i want to display a input type as password field but don't know how to do it

<div class="editor-field">
    @Html.EditorFor(model => model.Password)
    @Html.ValidationMessageFor(model => model.Password)
</div>
I want this field as hidden but i don't know how. Please help.
And also i want to check this field with
<div class="editor-label">
    Re-Password
</div>
<div class="editor-field">
    <input id="repwd" type="password" name="repwd"/>
</div>

to confirm if the password is correct

  1. Post:412

    Points:2888
    Re: Password field in C#

    Hi Mark,

    Use @Html.PasswordFor instead of @Html.EditorFor and for comparing two password your required to change model as show below

     public class ChangePasswordModel
     {
        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "New password")]
        public string NewPassword { get; set; }
        [DataType(DataType.Password)]
        [Display(Name = "Confirm new password")]
        [System.Web.Mvc.Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }
    }

      Modified On Apr-04-2018 02:12:52 AM

Answer