I'm developing an application using ASP.Net mvc.I have a sign up form.When a user enters the password ,I would like to encrypt the password and store in database.My code fails when I encrypt the password and try to insert it into the database. Please look at my code and let me know if it's wrong .
During Insertion ,I'm hitting the error : "Value cannot be null.Parameter name: input" My Controller is :
using CTCFremont.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
namespace CTCFremont.Controllers
{
public class UserLoginController : Controller
{
private CTCFremontEntities db = new CTCFremontEntities();
//
// GET: /UserLogin/Create
public ActionResult Index()
{
return View();
}
public ActionResult Create()
{
return View();
}
//
// POST: /UserLogin/Create
[HttpPost]
public ActionResult Create(UserLogin userlogin)
{
if (ModelState.IsValid)
{
userlogin.Pass = Crypto.SHA256(userlogin.Pass);
db.UserLogins.Add(userlogin);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(userlogin);
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
My view is :
@model CTCFremont.Models.UserLogin
@{
ViewBag.Title = "SignUp";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<h2>Sign Up!</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset >
<legend>Submit your details </legend>
<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field" >
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field" >
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Pass)
</div>
<div class="editor-field" >
@Html.EditorFor(model => model.Pass, new { id = "Password" })
@Html.ValidationMessageFor(model => model.Pass)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Confirm)
</div>
<div class="editor-field" >
@Html.EditorFor(model => model.Confirm, new { id = "Confirmation" })
@Html.ValidationMessageFor(model => model.Confirm)
</div>
<p>
<input type="submit" value="Submit" />
</p>
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}