Login page in MVC without database

Many times we need to pass some custom login credentials like username (email) and password. So that times we do not need to pass any database we direct check the credentials using if else conditions. In this article, we are trying to do same. Here we access the Html controls in controller using FormCollection. and also we will set pop up message of if  credentials fails 

Controller:- (loginController)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SMTS.Controllers
    public class loginController : Controller
        // GET: login
        public ActionResult Index()

            return View();
        public ActionResult loginform(FormCollection collection)
            string email = collection.Get("email");
            string Password = collection.Get("Password");
            if (email == "srinickraj@gmail.com" && Password == "1234")
                ViewBag.Message = "Please enter valid Email ID and Password";
            return View("Index");

    Layout = null;

<!doctype html>

    <!-- for-mobile-apps -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- //for-mobile-apps -->
    <link href="//fonts.googleapis.com/css?family=Abril+Fatface&amp;subset=latin-ext" rel="stylesheet">
    <link href='//fonts.googleapis.com/css?family=Roboto+Condensed:400,700italic,700,400italic,300italic,300' rel='stylesheet' type='text/css'>
    <!-- font-awesome icons -->
    <link href="~/Content/login/css/font-awesome.css" rel="stylesheet">
    <!-- //font-awesome icons -->
    @*<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
        <script src="js/jquery-2.1.4.min.js"></script>*@
    <link href="~/Content/login/css/style.css" rel="stylesheet" type="text/css" media="all" />
    <script src="~/Content/login/js/jquery-2.1.4.min.js"></script>
    @if (ViewBag.Message != null)

            $(document).ready(function () {




    <div class="content" id="Main-Content">
        <div class="w3ls-slider">
            <div class="hub-slider">
                <div class="hub-slider-slides">
                            <div class="login-form login-form-left">
                                <div class="agile-row">
                                    <h2>Sign In</h2>
                                    <div class="login-agileits-top">
                                        @using (Html.BeginForm("loginform", "login", FormMethod.Post))
                                            <input type="email" class="email" name="email" placeholder="Email" required="" />
                                            <input type="password" class="password" name="Password" placeholder="Password" required="" />


                                            <input type="submit" value="Sign In">

                                    <div class="login-agileits-bottom">
                                        <h6><a href="#">Forgot password?</a></h6>


        <!-- copyright -->
        <div class="copyright">
            <p>© 2017  All rights reserved</p>
        <!-- //copyright -->
        <script type="text/javascript" src="js/hubslider.js"></script>


Login page in MVC without database Login page in MVC without database Reviewed by NEERAJ SRIVASTAVA on 5:04:00 PM Rating: 5

1 comment:

Powered by Blogger.