Make a CMS (II)-Forms login verification

Source: Internet
Author: User

1. Configure web. config 
 
1: <authorization> <! -- Disable access by unauthorized users -->
   2:      <deny user="?"></deny>
   3:  </authorization>

 

2. Create a Login page

The file name and directory structure of the login page of this "things" must be like this "~ /Account/Login. cshtml "; the key code is as follows:

   1:  <form  method="post">
2: account <input name = "user" type = "text"/>
3: password <input name = "pass" type = "password"/>
4: <input name = "login" type = "submit" value = "Logon" class = "button"/>
   5:  </form>

Logic code:

1 :@{

   2:      var returnUrl = Request.QueryString["ReturnUrl"];
   3:      if(returnUrl.IsEmpty()){
   4:          returnUrl = "~/Admin/";
   5:      }
   6:      if(IsPost){
   7:          var username = Request.Form["user"];
   8:          var password = Request.Form["pass"];
   9:          var nickname = "";
  10:          var y = FormsAuthentication.HashPasswordForStoringInConfigFile(username+password,"md5");
  11:          var db = Database.Open("RazorCMS");
  12:          var sqlSel = "select TOP 1 username,password,nickname from SiteSet";
  13:          var user = db.QuerySingle(sqlSel);
  14:          var x = FormsAuthentication.HashPasswordForStoringInConfigFile(user["username"]+user["password"],"md5");
  15:          if(x==y){
  16:              nickname = user["nickname"];
  17:              FormsAuthentication.RedirectFromLoginPage(nickname,true);
  18:          }
  19:      }
  20:  }

3. Create Default. cshtml

Verify that the trend log on is successful:

   1:  @{
   2:      var n = Context.User.Identity.Name;
   3:  }
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.