|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace mvcForumapp.Controllers
{
public class LoginController : Controller
{
newForumDBEntities db = new newForumDBEntities();
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(mvcForumapp.Models.userModel user)
{
if (ModelState.IsValid)
{
if (isValid(user.Email, user.password))
{
var user1 = db.tblUsers.FirstOrDefault(u => u.EmailID == user.Email).UserName;
Session["UserName"] = user1;
//FormsAuthentication.SetAuthCookie(user.Email, false);
return RedirectToAction("Index", "Technology");
}
else
{
ModelState.AddModelError("", "Login Data is Incorrect");
}
}
return View(user);
}
private bool isValid(string Email, string password)
{
//string crypto = Encrypt(password, true);
bool isvalid = false;
using (var db = new newForumDBEntities())
{
var user = db.tblUsers.FirstOrDefault(u => u.EmailID == Email);
if (user != null)
{
if (user.Password == password)
{
isvalid = true;
}
}
}
return isvalid;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am working as a Software engineer. Web development in Asp.Net with C#, WinForms and MS sql server are the experience tools that I have had for the past 3 years. Yet to work on WCF, WPF, Silverlight and other latest ones.