@{
ViewData["Title"] = "Index";
}
@section css{
<link rel="stylesheet" type="text/css" href="~/css/Loingys.css" />
<link rel="stylesheet" type="text/css" href="~/css/Loingwdys.css" />
}
<div id="formContainer" class="dwo">
<div class="formLeft">
<img src="~/Publish/Mscdd.png">
</div>
<div class="formRight">
<!-- Forgot password form -->
<form id="forgot" class="otherForm">
<header>
<h1>忘记密码</h1>
<p>输入邮箱找回密码</p>
</header>
<section>
<label>
<span>邮箱</span>
<input type="email" placeholder=" ">
<span class="border"></span>
</label>
<button type="submit">发送邮件</button>
</section>
<footer>
<button type="button" class="forgotBtn">返回</button>
</footer>
</form>
<!-- Login form -->
<form action="User/Login" method="post">
<header>
<h1>欢迎回来</h1>
<p>请先登录</p>
</header>
<section>
<label>
<span style="color:#ffffff">用户名</span>
<input type="text" placeholder=" " id="LogName" name="LogName">
<span class="border"></span>
</label>
<label>
<span style="color:#ffffff">密码</span>
<input type="password" placeholder=" " id="Password" name="Password">
<span class="border"></span>
</label>
<div class="addboj">
<span style="color:#ffffff">验证码 </span>
<input type="text" id="validateCode" class="col-form-label-sm" />
<img id="imgVerify" src="~/User/ValidateCode" alt="看不清?点击更换" onclick="this.src = this.src + '?'" style="vertical-align:middle;" />
<span class="border"></span>
</div>
<br />
<span id="code" style="color:red;margin-left:100px;"></span>
<br />
<br />
<button type="submit" class="btn btn-primary" onclick="addPush()">登录</button>
</section>
<footer>
<button type="button" class="forgotBtn">忘记密码?</button>
<button type="button" class="registerBtn">新用户?</button>
</footer>
</form>
<!-- Register form -->
<form id="register" class="otherForm">
<header>
<h1>用户注册</h1>
<p>注册后享受更多服务</p>
</header>
<section>
<label>
<span>用户名</span>
<input type="text" placeholder=" ">
<span class="border"></span>
</label>
<label>
<span>邮箱</span>
<input type="email" placeholder=" ">
<span class="border"></span>
</label>
<label>
<span>密码</span>
<input type="password" placeholder=" ">
<span class="border"></span>
</label>
<label>
<span>重复密码</span>
<input type="password" placeholder=" ">
<span class="border"></span>
</label>
<button type="submit">注 册</button>
</section>
<footer>
<button type="button" class="registerBtn">返回</button>
</footer>
</form>
</div>
</div>
@section Scripts{
<script type="text/javascript">
$(function () {
});
var str = "?";
function addPush() {
$.ajax({
url: 'User/IzUserVoder',
dataType: 'JSON',
type: 'POST',
data: {
userVerCode: $("#validateCode").val()
},
success: function (date) {
if (date == "0") {
$("#imgVerify").attr("src", "Home/ValidateCode" + str)
$("#validateCode").val("");
$("#code").css("color", "red");
$("#code").html("验证码不正确");
str += str;
return;
}
$("#code").css("color", "#66FF59");
$("#code").html("验证码正确");
}
})
}
$(function () {
$('.forgotBtn').click(function () {
$('#forgot').toggleClass('toggle')
})
$('.registerBtn').click(function () {
$('#register, #formContainer').toggleClass('toggle')
})
})
</script>
}
public static string VerificationCodeCacheFormat = "vcode_cache_{0}";
public IActionResult ValidateCode()
{
VerificationCodeServices _vierificationCodeServices = new VerificationCodeServices();
string code = "";
System.IO.MemoryStream ms = _vierificationCodeServices.Create(out code);
code = code.ToLowerInvariant();
HttpContext.Session.SetString("SupportValidateCode", code);
Response.Body.Dispose();
var token = Guid.NewGuid().ToString();
Response.Cookies.Append("validatecode", token);
return File(ms.ToArray(), @"image/png");
}
public IActionResult IzUserVoder(string userVerCode)
{
if (VerifyUserInputCode(userVerCode))
{
HttpContext.Session.SetString("SupportValidateCode", "");
return Json(1);
}
return Json(0);
}
public bool VerifyUserInputCode(string userVerCode)
{
string vCode = HttpContext.Session.GetString("SupportValidateCode");
if (vCode != userVerCode) return false;
return true;
}
public IActionResult Login(string LogName, string Password)
{
if (string.IsNullOrEmpty(LogName))
{
return RedirectToAction("index");
}
if (string.IsNullOrEmpty(Password))
{
return RedirectToAction("index");
}
SystemUser data = hc.SystemUsers.Where(p => p.LogName == LogName.Trim()
&& p.Password == Password.Trim()).FirstOrDefault();
if (data == null)
{
return RedirectToAction("index");
}
HttpContext.Session.SetString("logName", data.LogName);
return RedirectToAction("list");
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DbCore.Model.Models
{
public class VerificationCodeServices
{
private string RndomStr(int codeLength)
{
string chars = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,P,Q,R,S,T,U,V,W,X,Y,Z";
string[] charArray = chars.Split(new Char[] { ',' });
string code = "";
int temp = -1;
Random rand = new Random();
for (int i = 1; i < codeLength + 1; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));
}
int t = rand.Next(61);
if (temp == t)
{
return RndomStr(codeLength);
}
temp = t;
code += charArray[t];
}
return code;
}
public MemoryStream Create(out string code, int length = 4)
{
code = RndomStr(length);
Bitmap Img = null;
Graphics graphics = null;
MemoryStream ms = null;
Random random = new Random();
Color[] color = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };
string[] fonts = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" };
Img = new Bitmap((int)code.Length * 18, 32);
graphics = Graphics.FromImage(Img);
graphics.Clear(Color.White);
for (int i = 0; i < 100; i++)
{
int x = random.Next(Img.Width);
int y = random.Next(Img.Height);
graphics.DrawRectangle(new Pen(Color.LightGray, 0), x, y, 1, 1);
}
for (int i = 0; i < code.Length; i++)
{
int colorIndex = random.Next(7);
int fontIndex = random.Next(4);
Font font = new Font(fonts[fontIndex], 15, FontStyle.Bold);
Brush brush = new SolidBrush(color[colorIndex]);
int y = 4;
if ((i + 1) % 2 == 0)
{
y = 2;
}
graphics.DrawString(code.Substring(i, 1), font, brush, 3 + (i * 12), y);
}
ms = new MemoryStream();
Img.Save(ms, ImageFormat.Png);
graphics.Dispose();
Img.Dispose();
return ms;
}
}
}