---
title: "Password field in C#"  
description: "Password field in C#"  
author: "Mark Devid"  
published: 2014-01-28  
updated: 2014-01-29  
canonical: https://www.mindstick.com/forum/1902/password-field-in-c-sharp  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# Password field in C#

I am using [entity framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) and .net 4.5 with c#5 for first time from last 2-3 [days](https://www.mindstick.com/articles/157271/how-to-get-cloudways-free-trial-for-14-days-free) and i want to display a [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) type as [password](https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net) [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) 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](https://www.mindstick.com/forum/2303/skip-validating-field-from-hidden-div) but i don't know how. Please help.\
And also i want to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) this field with\

```
<div class="editor-label">    Re-Password</div><div class="editor-field">    <input id="repwd" type="password" name="repwd"/></div>
```

to [confirm](https://answers.mindstick.com/qa/115761/facebook-account-locked-with-confirm-your-identity-loop) if the password is correct

## Replies

### Reply by Pravesh Singh

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; }}
```


---

Original Source: https://www.mindstick.com/forum/1902/password-field-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
