网站登录时记住密码

UI层一个登录框,一个密码框,一个验证码框 ,然后一个记住密码

<div class="banner">

<div class="login-aside">

<div id="o-box-up" style="height:400px"></div>

<div id="o-box-down" style="table-layout:fixed;height:400px;">

<div class="error-box"></div>

<form class="registerform" method="post" action="/shop/account/login">

<input type="hidden" value="@ViewBag.returnUrl" name="url" />

<div class="fm-item">

<label for="logonId" class="form-label">用户登录:</label>

@*<input type="text" value="请输入账号" maxlength="100" id="username" class="i-text" >*@

@Html.TextBoxFor(m => m.username, new {@class="i-text",@placeholder="请输入账号" })<br />

@Html.ValidationMessageFor(m=>m.username)

<div class="ui-form-explain"></div>

</div>

<div class="fm-item">

<label for="logonId" class="form-label">输入密码:</label>

@*<input type="password" name="password" value="" maxlength="100" id="password" class="i-text" >*@

@Html.PasswordFor(m => m.password, new { @class="i-text",@placeholder="请输入密码"})<br />

@Html.ValidationMessageFor(m=>m.password)

<div class="ui-form-explain"></div>

</div>

<div class="fm-item pos-r">

<label for="logonId" class="form-label">验证码</label>

@*<input type="text" id="authInput" value="输入验证码"  id="yzm" class="i-text yzm" >*@

@Html.TextBoxFor(m => m.authInput, new {@class="i-text yzm",@placeholder="请输入验证码" })

<div class="ui-form-explain"><img id="authCode" height="38" width="80" src="/shop/account/authCode" onclick="this.src=‘/shop/account/authCode?r=‘+Math.random()" class="yzm-img" /></div>

</div>

<div class="fm-item" style="padding-top:10px">

@Html.CheckBoxFor(m=>m.isRemember)

@*<input type="checkbox" />*@

<span class="remember" style="line-height: 12px;text-align: left;width: auto;font-size: 14px; color: #fff; font-weight: bold; ">记住密码</span>

<div class="findPass">

<a class="findpassLink" href="#" style="display:none;">忘记密码</a>

</div>

</div>

<div class="fm-item">

<label for="logonId" class="form-label">@Html.ValidationMessage("error")</label>

<input type="submit" value="登录" tabindex="4" id="send-btn" class="btn-login">

</div>

</form>

</div>

</div>

controller中第一个是登录,登录的时候验证是否勾选了记住密码 ,记住了就存入cookie

#region 登陆

/// <summary>

/// 登陆

/// </summary>

/// <param name="url">返回页面</param>

/// <returns></returns>

[HttpGet]

public ActionResult login(string url = "")

{

ViewBag.userInfo = getRUserInfo();

ViewBag.returnUrl = url;

return View();

}

/// <summary>

/// 执行登陆

/// </summary>

/// <param name="userName"></param>

/// <param name="passWord"></param>

/// <param name="authCode"></param>

/// <param name="isRemember"></param>

/// <returns></returns>

[HttpPost]

public ActionResult login(shopModel model, string url)

{

string mess = "serverErr";

if (Session["auth"] != null)

{

if (ModelState.IsValid)

{

if (Session["auth"].ToString().ToLower() == model.authInput.ToLower())

{

//string md5_pass = getMD5Code(model.password);//密码

DataProtectionProxy.DataProtectionProxy dp = new DataProtectionProxy.DataProtectionProxy();

if (String.IsNullOrEmpty(model.password))

model.password = "";

else

model.password= dp.Encrypt(model.password);

Web.Model.WeiXin.User user = new AccountHandler().login(model.username, model.password);

if (user != null)

{

Session["wx_user"] = user;

if (model.isRemember)

{

addRUserInfo(new Web.Model.WeiXin.User() { loginname = model.username, password = model.password });

}

else

{

deleteRUserInfo();

}

if (string.IsNullOrEmpty(url))

{

return Redirect("/shop/order/shopcart");

}

else

{

return Redirect(url);

}

}

else

{

ModelState.AddModelError("error", "用户名或密码输入错误");

}

}

else

{

ModelState.AddModelError("error", "验证码输入错误");

}

}

}

ViewBag.returnUrl = url;

return View();

}

/// <summary>

/// 登出操作

/// </summary>

/// <returns></returns>

[HttpPost]

public ActionResult logout()

{

Session.Remove("wx_user");

return Content("success");

}

#endregion

#region  修改记录用户信息

/// <summary>

/// 设置本地记录用户信息

/// </summary>

/// <param name="user"></param>

public void addRUserInfo(Web.Model.WeiXin.User user)

{

string userInfo = Newtonsoft.Json.JsonConvert.SerializeObject(user);

HttpCookie cookie = new HttpCookie("r_userInfo");

cookie.Value = HttpUtility.UrlEncode(userInfo, Encoding.UTF8);

cookie.Expires = DateTime.Now.AddDays(7);

Response.Cookies.Add(cookie);

}

/// <summary>

/// 获取本机记录用户信息

/// </summary>

/// <returns></returns>

public Web.Model.WeiXin.User getRUserInfo()

{

Web.Model.WeiXin.User user = newWeb.Model.WeiXin.User();

if (Request.Cookies["r_userInfo"] != null)

{

JsonSerializer jserial = new JsonSerializer();

StringReader strread = new StringReader(HttpUtility.UrlDecode(Request.Cookies["r_userInfo"].Value, Encoding.UTF8));

user = jserial.Deserialize<TeenySoft.Web.Model.WeiXin.User>(new JsonTextReader(strread));

return user;

}

return null;

}

/// <summary>

/// 删除本机记录用户信息

/// </summary>

public void deleteRUserInfo()

{

if (Request.Cookies["r_userInfo"] != null)

{

Response.Cookies["r_userInfo"].Expires = DateTime.Now.AddDays(-1);

Response.Cookies.Set(Response.Cookies["r_userInfo"]);

}

}

#endregion

#region  验证码

/// <summary>

/// 图片验证码

/// </summary>

public void authCode()

{

string authCode = getAuthCode();

Session["auth"] = authCode;

Response.ContentType = "image/jpeg";

createActhImg(authCode).Save(Response.OutputStream, ImageFormat.Jpeg);

}

/// <summary>

/// 生成验证码图片

/// </summary>

/// <param name="authCode"></param>

/// <returns></returns>

public Image createActhImg(string authCode)

{

Bitmap result = null;

//创建绘图

result = new Bitmap(authCode.Length * 16, 25);

using (Graphics objGraphics = Graphics.FromImage(result))

{

objGraphics.SmoothingMode = SmoothingMode.HighQuality;

//清除整个绘图面并以指定背景色填充

objGraphics.Clear(Color.AliceBlue);

//创建画笔

using (SolidBrush objSolidBrush = new SolidBrush(Color.Black))

{

this.AddForeNoisePoint(result);

this.AddBackgroundNoisePoint(result, objGraphics);

//文字居中

StringFormat objStringFormat = new StringFormat(StringFormatFlags.NoClip);

objStringFormat.Alignment = StringAlignment.Center;

objStringFormat.LineAlignment = StringAlignment.Center;

//字体样式

Font objFont = new Font(FontFamily.GenericSerif, objRandom.Next( 18- 3, 18), FontStyle.Regular);

//验证码旋转,防止机器识别

char[] chars = authCode.ToCharArray();

for (int i = 0; i < chars.Length; i++)

{

//转动的度数

float angle = objRandom.Next(-randomAngle,randomAngle);

objGraphics.TranslateTransform(12, 12);

objGraphics.RotateTransform(angle);

objGraphics.DrawString(chars[i].ToString(), objFont, objSolidBrush, -2, 2, objStringFormat);

objGraphics.RotateTransform(-angle);

objGraphics.TranslateTransform(2, -12);

}

}

}

return result;

}

/// <summary>

/// 添加前景噪点

/// </summary>

/// <param name="objBitmap"></param>

private void AddForeNoisePoint(Bitmap objBitmap)

{

for (int i = 0; i < objBitmap.Width * this.foreNoisePointCount; i++)

{

objBitmap.SetPixel(objRandom.Next(objBitmap.Width), objRandom.Next(objBitmap.Height), Color.SeaGreen);

}

}

/// <summary>

/// 添加背景噪点

/// </summary>

/// <param name="objBitmap"></param>

/// <param name="objGraphics"></param>

private void AddBackgroundNoisePoint(Bitmap objBitmap, Graphics objGraphics)

{

using (Pen objPen = new Pen(Color.Azure, 0))

{

for (int i = 0; i < objBitmap.Width * 2; i++)

{

objGraphics.DrawRectangle(objPen, objRandom.Next(objBitmap.Width), objRandom.Next(objBitmap.Height), 1, 1);

}

}

}

/// <summary>

/// 生成验证码

/// </summary>

/// <returns></returns>

public string getAuthCode()

{

string authCode = "";

Random rand = new Random();

for (int i = 0; i < 4; i++)

{

int action = rand.Next(2);

switch (action)

{

case 0:

authCode += (char)rand.Next(48, 58);

break;

case 1:

authCode += (char)rand.Next(65, 91);

break;

}

}

return authCode;

}

/// <summary>

/// MD5编码

/// </summary>

/// <param name="pwd"></param>

/// <returns></returns>

public string getMD5Code(string pwd)

{

byte[] result = Encoding.Default.GetBytes(pwd);    //tbPass为输入密码的文本框

MD5 md5 = new MD5CryptoServiceProvider();

byte[] output = md5.ComputeHash(result);

return BitConverter.ToString(output).Replace("-", "");  //tbMd5pass为输出加密文本的文本框

}

#endregion

时间: 2024-10-11 15:51:29

网站登录时记住密码的相关文章

电脑端TIM登录时记住密码

为什么每次登录TIM时点了记住密码,下次再登录时还是记不住呢? 不是扫码就是还得输出密码,为这事愁了好多次, 最近终于发现如何记住密码了... 进入登录界面以后,点击左下角这个小图标>> 再点击 ,把自己的账号添加进去就ok啦~~~ 原文地址:https://www.cnblogs.com/newfirst-lzx/p/12153096.html

配置 OWA 下次登录时更改密码

配置 OWA 下次登录时更改密码 在大多数情况下,管理员在为新用户建立完域用户帐户时,需要用户在下次登录时更改密码.在用户的密码快要到期时也需要用户可以在OWA中修改登录密码. 本文只针对Exchange 2010 SP1进行说明,没有升级到Exchange 2010 SP1的朋友,请将你的Exchange Server 2010 升级到Exchange Server 2010 SP1,配置 OWA 下次登录时更改密码时可以应用在管理员在为新用户建立账户时配置用户在下次登录时必须修改密码,还可以

登录之回车登录和记住密码

页面: <div> <dl> <dd><input name="txtUser" type="text" id="txtUser" placeholder="用户名/邮箱/手机号" /> </dd> </dl> <dl> <dd><input type="password" id="Userpwd

Android实战(一)学习了多个控件实现登录及记住密码功能

首先确定一下需要的控件: 两个EditText:用于输入账号和密码 一个button:用于登录查看账号和密码是否正确 一个checkbox:用于记住密码和账户 一个Androidstudio:用于编写代码,当然牛逼的人也推荐使用记事本写代码,废话不多说开工. 创建一个App项目加入两个布局两份Java.class ,在Androidmanifest.xml里面注册第二个布局. 准备完毕 1.在初始布局中加入上述控件,并为其设置好id 代码如下所示 <LinearLayout xmlns:andr

Android自动登录与记住密码

// 获取实例对象 sp = this.getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE); rem_pw = (CheckBox) findViewById(R.id.cb_mima); auto_login = (CheckBox) findViewById(R.id.cb_auto); // 判断记住密码多选框的状态 if (sp.getBoolean("ISCHECK", false))

下次自动登录(记住密码)功能

1:进入cookie插件 <script src="jquery.cookie.js" type="text/javascript"></script> 2:登录界面 <input type="checkbox" id="autologin" /><label for="autologin">下次自动登录</label> :3:登录方法:如果登录成

JavaWeb学习记录总结(二十九)--Servlet\Session\Cookie\Filter实现自动登录和记住密码

一.Servlet package autologin.servlet.login; import java.io.IOException;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException; import javax.servlet.ServletException;import javax.servlet.http.Cookie;import javax.servlet.http.H

Java使用SSM框架实现登录页面记住密码功能

最终效果展示: 1.登录页面JSP代码 <label class="checkbox"> <input type="checkbox" name="rememberMe" id="rememberMe" onclick="remember();"/> 记住密码 </label> //选中记住密码触发事件,如果选中就赋值为1 ,否则赋值为0 function remembe

对于登录窗口记住密码的相关应用升级

这次主要是做的怎样实现登录窗口的,自主密码操作.当点击记住密码之后,下次登录此账号的时候,当输入账号中失去节点的时候,就会触发相关的事件. 当登录的时候取消了记住密码的点击事件下次登录的时候就不会自动添加密码了, 刚开始的思路是想网上学习的资料一样,通过MAP并将其对应的密码账号添加到新的文件夹中. 每次在登录账号后,会在此自动添加相关的密码.实现登录. 这个的更新是省去了关于文件的先关的操作. 知识在保存用户登录是用到的数据库增加了一个项目.实现判定当前账户时候确定了记住密码操作. 具体的数据