This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<connectionStrings> | |
<add name="StudentDBContext" | |
connectionString="Data Source=(LocalDB)\mssqllocaldb;Initial Catalog=StudentDB;Integrated Security=True;" | |
providerName="System.Data.SqlClient" /> | |
</connectionStrings> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StudentDBContext : DbContext | |
{ | |
public DbSet<Student> Students { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Index() | |
{ | |
return View(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoginModel | |
{ | |
public string UserName { get; set; } | |
public string Password { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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"; |