C#-Mvc-修改密码

继续调用MyWebApp类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Droplets.Models;
using System.Web;

namespace Droplets.WebCode
{
public static class MyWebApp
{
private const string SessionUser = "CurrentUser";
public const string LoginUrl = "/Management/Login";
public const string LogoutUrl = "/Management/Logout";

public static Admin currentUser
{
get
{
if (HttpContext.Current == null) return null;
return HttpContext.Current.Session[SessionUser] as Admin;
}
set
{
HttpContext.Current.Session[SessionUser] = value;
}
}
public static Admin checkLogin()
{
var user = currentUser;
if (user == null)
{
HttpContext.Current.Response.Redirect(LoginUrl);
}
return user;
}
public static void logout()
{
HttpContext.Current.Session.Remove(SessionUser);
}
}
}

Index.View部分:

@model Droplets.Models.Admin
@using Droplets.Models
@using Droplets.WebCode
@{
Layout = null;
Admin admin = MyWebApp.currentUser;
string message = ViewBag.message;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/easyui.css" rel="stylesheet" />
<link href="~/Content/icon.css" rel="stylesheet" />
<link href="~/Content/demo.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.easyui.min.js"></script>
<title>修改密码</title>
<script type="text/javascript">

function submitForm() {
var oldpass = $(‘#oldpass‘).val();
var newpass = $(‘#newpass‘).val();
var newpass1 = $(‘#newpass1‘).val();
if (newpass != newpass1) {
alert(‘两次输入的新密码不一致!‘)
return false;
}
if (oldpass == newpass && newpass == newpass1)
{
alert(‘新密码不能和旧密码相同!‘)
return false;
}

$(‘#form1‘).submit();
}
function reset(){
$(‘#form1‘).form(‘clear‘);
}

</script>
@if (!string.IsNullOrEmpty(message))
{
<script type="text/javascript">
$(function() {
alert("@message");
});
</script>
}
<style type="text/css">
#div1 {
position: absolute;
top: 50%;
left: 50%;
margin: -150px 0 0 -200px;
border: 1px solid #008800;
}
</style>
</head>
<body>
<div id="div1">
<div class="easyui-panel" title="密码修改" style="width:500px;padding:30px 60px">
<div style="margin-bottom:30px">
<form method="post" id="form1" action="/Admin/Index">
<table>
<tbody>
<tr style="margin-bottom:20px">
<td><label>用户名:</label></td>
<td><lable>@admin.Name</lable></td>
</tr>
<tr style="margin-bottom:20px">
<td><lable>旧密码:</lable></td>
<td><input class="easyui-textbox" id="oldpass" type="password" name="oldpass"></td>
</tr>
<tr style="margin-bottom:20px">
<td><lable>新密码:</lable></td>
<td><input class="easyui-textbox" id="newpass" type="password" name="newpass"></td>
</tr>
<tr style="margin-bottom:20px">
<td><lable>确认新密码:</lable></td>
<td><input class="easyui-textbox" id="newpass1" type="password" name="newpass1"></td>
</tr>
</tbody>
</table>
<div style="margin-top:30px">
<a href="#" class="easyui-linkbutton" onclick="submitForm()" style="width:20%;margin-left:10%">提交</a>
<a href="#" class="easyui-linkbutton" onclick="reset()" style="width:20%;margin-left:10%">重置</a>
@*<input type="submit" value="提交" style="width:60px;height:30px;margin-right:50px" />
<input type="reset" value="取消" style="width:60px;height:30px" />*@
</div>
</form>
</div>
</div>
</div>

</body>
</html>

AdminController部分:

public class AdminController : Controller
{
//
// GET: /Admin/
Droplets.Models.DropletsEntities db;

public AdminController()
{
db = new DropletsEntities();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
public ActionResult Index()
{
var admin = MyWebApp.checkLogin();//监察当前用户是否登录
if (admin == null)
{
return RedirectToAction("/Managemnet/Login");
}
return View();
}
[HttpPost]
[ActionName("Index")]
public ActionResult IndexPost()
{
string AdminName = MyWebApp.currentUser.Name;
var temp = db.Admin.FirstOrDefault(t => t.Name == AdminName);
string pas = temp.PassWord;
if (pas != Request.Form["oldpass"])
{
ViewBag.message = "旧密码输入错误";

}
else {
temp.PassWord = Request.Form["newpass"];
db.SaveChanges();
ViewBag.message = ("密码修改成功!");
}
return View("Index");
}

}

}

时间: 2024-08-10 07:03:19

C#-Mvc-修改密码的相关文章

MVC5 网站开发之六 管理员功能之添加、删除、重置密码、修改密码、列表浏览

  一.安装插件. 展示层前端框架以Bootstrap为主,因为Bootstrap的js功能较弱,这里添加一些插件作补充.其实很多js插件可以通过NuGet安装,只是NuGet安装时添加的内容较多,不如自己复制来的干净,所以这里所有的插件都是下载然后复制到项目中. 1.Bootstrap 3 Datepicker 4.17.37 网址:https://eonasdan.github.io/bootstrap-datetimepicker/ 下载并解压压缩包->将bootstrap-datetim

在Exchange 2013 OWA登录页面中修改密码

透过OWA登录界面改密码对于使用Exchange的用户来说是一个很有有用的功能. 因为如果用户不在公司域环境中,当密码已经到期登录不了OWA,就没有办法通过OWA中的[选项]来改密码,当开启这项功能后,管理员和用户都可以很方便的处理密码到期的case. 早在Exchange2010的时候,我们需要通过修改CAS服务器的注册表项来实现这个功能.现在的Exchange2013已经内置了该功能,使用前只需要确认该功能属性的状态就可以了. 在最新的Exchange2013 SP1和CU5版本中,此功能在

Win7修改密码策略

第一步.Win+R打开cmd窗口输入gpedit.msc 第二步.修改密码策略(打开"计算机配置"-->"安全设置"-->"账户策略"-->"密码策略") 第三步.修改密码复杂度.密码使用期限 第四步.设置密码锁定次数 第五步.cmd下设置密码[net user administrator Hell0!jie]

MySQL5.7修改密码

MySQL5.7出来蛮久了,今天用官方的RPM包安装玩了一遍,与值之前的版本有些差异,MARK下. OS PLATFORM:Centos 7.3 安装MySQL 5.7版本,官网http://dev.mysql.com/downloads/repo/yum/ rpm -ivh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm YUM安装: yum -y install mysql-community-serv

mysql 5.1版本 修改密码,及远程登录mysql数据库

mysql创建用户并授权:   格式:grant 权限 on 数据库名.表名 to 用户@登录主机 identified by "用户密码"; grant[英][grɑ:nt]   承认; 同意; 准许; 授予;  例1:允许mk用户从localhost登录 mysql>  grant all on book.* to [email protected] identified by "123456";  #允许访问book数据库下的所有表, 只能访问book表

mysql多实例忘记root密码,修改密码

1.修改配置参数 /etc/my.cnf 在 [mysqld3306] 下面加上: skip-grant-tables 2.重启MySQL mysqld_multi start 3306 3.修改密码 mysql -h127.0.0.1 -P3306 -uroot update mysql.user set password=password('test_new2_password') where user= 'root'; flush privileges; 关闭数据库 mysqld_mult

mysq安装以及修改密码

安装版MySQL是不能一键安装的,下载下来是压缩包,解压后只要进行相关配置就可以正常使用: 文章主要是记录一下,以防自己忘记: 1.首先在mysql官网--http://dev.mysql.com/downloads/mysql/  下载mysql: 2.下载后解压到对应路径 我是放在 D:\mysql-5.7.14-winx64\ 里面,解压完后改名,可以自己进行重命名: 3.配置环境变量 找到--高级系统变量--环境变量--系统变量 新建环境变量:变量名 MYSQL_HOME,变量值 D:\

python 随机远程主机修改密码

执行脚本需要有以下前提: 主机与客户机配置互信(ssh 无密码认证登录) 需要读取当前目录下的host文件,里面是连接远程主机的ip地址 脚本可以修改远程主机为ubuntu和centos的密码 代码如下: #!/usr/bin/env python #coding:utf-8 import paramiko import platform import sys,os import threading import time def color_print(msg, color='red', ex

mysql数据库忘记密码后如何修改密码

当我们忘记mysql数据库密码时我们就无法正常进入数据库,也就无法修改密码,那么这时该怎么修改密码呢,这里教大家一个简单常用修改密码的方式. 方法/步骤 1 打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 2 打开cmd命令提示符,进入上一步mysql.exe所在的文件夹. 3 输入命令  mysqld --skip-grant-tables  回车,此时就跳过了mysql的用户验证.注意输入此命令之后命令行就无法操作了,此时可以再打开一个新的命令行.注意:在输入此命令之

centos7下mariadb 首次修改密码及忘记密码处理方法

首次修改密码 第一种 >mysqladmin -u root -p[oldpass] password newpass 注意oldpass(老密码)可选,如果root默认密码为空,则不需要输入 如果需要更改老密码,请注意老密码与-p之间不要有空格,否则会报错,另外password和newpass(新密码)之间以空格分隔. 第二种 初始化数据库 /usr/local/mysql/bin/mysql_secure_installation                yum安装是在/usr/bin