Skip to content

Instantly share code, notes, and snippets.

<connectionStrings>
<add name="StudentDBContext"
connectionString="Data Source=(LocalDB)\mssqllocaldb;Initial Catalog=StudentDB;Integrated Security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using DataBaseDemo.Models;
@model ValidationDemo.Models.Student
@{
ViewBag.Title = "Index";
}
<h2>ASP.NET MVC DataAnnotations Validation</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Student</h4>
public class Student
{
[Key]
public int ID { get; set; }
[Required(ErrorMessage = "Please Enter Name"), MaxLength(20)]
[Display(Name = "First Name")]
[DataType(DataType.Text)]
public string FirstName { get; set; }
public class StudentDBContext : DbContext
{
public DbSet<Student> Students { get; set; }
}
public ActionResult Index()
{
return View();
}
public class LoginModel
{
public string UserName { get; set; }
public string Password { get; set; }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TwoFactorAuthenticationDemo.Models;
using Google.Authenticator;
namespace TwoFactorAuthenticationDemo.Controllers
{
@model TwoFactorAuthenticationDemo.Models.LoginModel
@{
ViewBag.Title = "Login";
}
<h2>Login Page</h2>
@if (ViewBag.Status == null || !ViewBag.Status)
{
<div>@ViewBag.Message</div>
<div>
@using (Html.BeginForm())
[HttpPost]
public ActionResult Login(LoginModel login)
{
string message = "";
bool status = false;
//check UserName and password form our database here
if (login.UserName == "Admin" && login.Password == "12345") // Admin as user name and 12345 as Password
{
status = true;
message = "Two Factor Authentication Verification";