Bad md5 hash for package

解决Python chardet安装问题
本文介绍了解决在Python环境中安装chardet版本2.2.1时遇到的MD5校验错误的方法,提供了通过直接下载whl文件并使用pip进行安装的步骤。
[root@master conn]# pip install chardet==2.2.1
Collecting chardet==2.2.1
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading chardet-2.2.1-py2.py3-none-any.whl (180kB)
    72% |███████████████████████▎        | 131kB 357bytes/s eta 0:02:19
  Hash of the package https://pypi.python.org/packages/2.7/c/chardet/chardet-2.2.1-py2.py3-none-any.whl#md5=556de73cc5d2d14233b3512798423da1 (from https://pypi.python.org/simple/chardet/) (be001cd2dbe90bb1f1dd4ab4b008c169) doesn't match the expected hash 556de73cc5d2d14233b3512798423da1!

  Bad md5 hash for package https://pypi.python.org/packages/2.7/c/chardet/chardet-2.2.1-py2.py3-none-any.whl#md5=556de73cc5d2d14233b3512798423da1 (from https://pypi.python.org/simple/chardet/)



解决方案:

wget https://pypi.python.org/packages/2.7/c/chardet/chardet-2.2.1-py2.py3-none-any.whl --no-check-certificate

md5sum chardet-2.2.1-py2.py3-none-any.whl

pip install chardet-2.2.1-py2.py3-none-any.whl

转载于:https://my.oschina.net/muyexia/blog/416197

package com.qf.controller; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.qf.service.UserChangePasswordService; import com.qf.service.UserService; import com.qf.util.Response; import com.qf.util.Response1; import com.qf.util.*; // 推荐 // 或 import com.qf.util.Response; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import java.util.Map; // src/main/java/com/qf/controller/ChangePasswordServlet.java // ✅ ChangePasswordServlet最终改进版 @WebServlet("/api/student/changePassword") public class ChangePasswordServlet extends HttpServlet { private UserChangePasswordService userChangePasswordService = new UserChangePasswordService(); private ObjectMapper objectMapper = new ObjectMapper(); protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); try { HttpSession session = request.getSession(false); if (session == null || session.getAttribute("userId") == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); out.write(objectMapper.writeValueAsString(Response1.error("未登录"))); return; } JsonNode jsonNode = objectMapper.readTree(request.getInputStream()); String oldPassword = jsonNode.get("oldPassword").asText(); String newPassword = jsonNode.get("newPassword").asText(); boolean result = userChangePasswordService.changePassword( (Long) session.getAttribute("userId"), oldPassword, newPassword ); if (result) { session.invalidate(); // 修改密码后强制登出 out.write(objectMapper.writeValueAsString(Response1.success("密码修改成功"))); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.write(objectMapper.writeValueAsString(Response1.error("旧密码错误"))); } } catch (SQLException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write(objectMapper.writeValueAsString(Response1.error("系统错误"))); } finally { out.close(); } } } package com.qf.dao; import com.qf.entity.User; import com.qf.util.DatabaseUtil; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class UserDao { public User findByUsername(String username) throws SQLException { String sql = "SELECT * FROM sys_user WHERE username = ?"; try (Connection connection = DatabaseUtil.getConnection(); PreparedStatement ps = connection.prepareStatement(sql)) { ps.setString(1, username); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { User user = new User(); user.setUserId(rs.getLong("user_id")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setSalt(rs.getString("salt")); user.setRole(rs.getInt("role")); user.setStatus(rs.getInt("status")); return user; } } } return null; } // 更新用户密码和盐值 public boolean updatePassword(Long userId, String hashedPassword, String salt) throws SQLException { String sql = "UPDATE sys_user SET password = ?, salt = ? WHERE user_id = ?"; try (Connection conn = DatabaseUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, hashedPassword); ps.setString(2, salt); ps.setLong(3, userId); return ps.executeUpdate() > 0; } } // 获取用户密码(用于验证旧密码) public String getPasswordByUserId(Long userId) throws SQLException { String sql = "SELECT password FROM sys_user WHERE user_id = ?"; try (Connection conn = DatabaseUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setLong(1, userId); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { return rs.getString("password"); } } } return null; } public User getUserWithPassword(Long userId) throws SQLException { String sql = "SELECT password, salt FROM sys_user WHERE user_id = ?"; try (Connection conn = DatabaseUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) { ps.setLong(1, userId); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { User user = new User(); user.setPassword(rs.getString("password")); user.setSalt(rs.getString("salt")); return user; } } } return null; } } package com.qf.service; import com.qf.dao.UserDao; import com.qf.entity.User; import com.qf.util.PasswordUtil1; import java.sql.SQLException; public class UserChangePasswordService { private UserDao userDao = new UserDao(); // 修改密码的方法 public boolean changePassword(Long userId, String oldPassword, String newPassword) throws SQLException { // 1. 获取用户密码和盐值 User user = userDao.getUserWithPassword(userId); if (user == null) return false; String storedPassword = user.getPassword(); String salt = user.getSalt(); // 2. 使用盐值验证旧密码 if (!storedPassword.equals(PasswordUtil1.hashPassword(oldPassword + salt))) { return false; } // 3. 生成新盐值和加密密码 String newSalt = PasswordUtil1.generateSalt(); String hashedNewPassword = PasswordUtil1.hashPassword(newPassword + newSalt); // 4. 更新数据库 return userDao.updatePassword(userId, hashedNewPassword, newSalt); } } package com.qf.util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.UUID; public class PasswordUtil1 { public static String generateSalt() { return UUID.randomUUID().toString(); } // ✅ 加密方法保持一致性 public static String hashPassword(String input) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] hash = md.digest(input.getBytes()); StringBuilder hexString = new StringBuilder(); for (byte b : hash) { String hex = Integer.toHexString(0xff & b); if (hex.length() == 1) hexString.append('0'); hexString.append(hex); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } } package com.qf.util; // ✅ src/main/java/com/qf/util/Response.java public class Response1 { private String status; private String message; public static Response1 success(String message) { return new Response1("success", message); } public static Response1 error(String message) { return new Response1("error", message); } private Response1(String status, String message) { this.status = status; this.message = message; } // Getters public String getStatus() { return status; } public String getMessage() { return message; } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>学生后台管理</title> <link rel="stylesheet" href="css/student.css"> </head> <body> <div class="container"> <h1>学生后台管理</h1> <div class="menu"> <button id="viewProfile">查看个人信息</button> <button id="selectCourse">选课</button> <button id="viewGrades">查看成绩/课表</button> <button id="changePassword">修改密码</button> </div> <div id="content"></div> </div> <script src="js/jquery-2.1.0.min.js"></script> <script> $(document).ready(function() { // 查看个人信息 $('#viewProfile').click(function() { $.ajax({ url: '/api/student/profile', type: 'GET', dataType:"json", success: function(data) { console.log(data) let content = `<h2>个人信息</h2> <p>姓名: ${data.name}</p> <p>学号: ${data.stuNumber}</p> <p>班级: ${data.classId}</p> <p>性别: ${data.gender === 1 ? '男' : '女'}</p> <p>电话: ${data.phone}</p> <p>邮箱: ${data.email}</p>`; $('#content').html(content); }, error: function() { $('#content').html('<p>加载个人信息失败</p>'); } }); }); // 选课 $('#selectCourse').click(function() { $.ajax({ url: '/api/student/courses', type: 'GET', success: function(data) { let content = `<h2>选课</h2> <form id="selectCourseForm"> <label for="courseId">课程ID</label> <input type="text" id="courseId" name="courseId" required> <button type="submit">选课</button> </form>`; $('#content').html(content); // 提交选课表单 $('#selectCourseForm').on('submit', function(event) { event.preventDefault(); let courseId = $('#courseId').val(); $.ajax({ url: '/api/student/selectCourse', type: 'POST', data: { courseId: courseId }, success: function(response) { alert(response.message); }, error: function() { alert('选课失败'); } }); }); }, error: function() { $('#content').html('<p>加载选课信息失败</p>'); } }); }); // 查看成绩/课表 $('#viewGrades').click(function() { $.ajax({ url: '/api/student/grades', type: 'GET', success: function(data) { let content = `<h2>成绩/课表</h2> <table> <thead> <tr> <th>课程ID</th> <th>课程名称</th> <th>成绩</th> </tr> </thead> <tbody>`; data.forEach(function(grade) { content += `<tr> <td>${grade.courseId}</td> <td>${grade.courseName}</td> <td>${grade.grade}</td> </tr>`; }); content += `</tbody></table>`; $('#content').html(content); }, error: function() { $('#content').html('<p>加载成绩/课表失败</p>'); } }); }); // 修改密码 // src/main/webapp/dashboard.html 修改密码部分 // ✅ 完整表单生成代码 $('#changePassword').click(function() { let content = `<h2>修改密码</h2> <form id="changePasswordForm" class="password-form"> <div class="form-group"> <label for="oldPassword">旧密码</label> <input type="password" id="oldPassword" name="oldPassword" required> </div> <div class="form-group"> <label for="newPassword">新密码</label> <input type="password" id="newPassword" name="newPassword" required> </div> <div class="form-group"> <label for="confirmPassword">确认密码</label> <input type="password" id="confirmPassword" name="confirmPassword" required> </div> <button type="submit">修改密码</button> </form>`; $('#content').html(content); }); // ✅ 使用事件委托绑定动态表单 $('#content').on('submit', '#changePasswordForm', function(event) { event.preventDefault(); // 表单验证逻辑 let oldPassword = $('#oldPassword').val().trim(); let newPassword = $('#newPassword').val().trim(); let confirmPassword = $('#confirmPassword').val().trim(); // 密码一致性校验 if (!oldPassword || !newPassword || !confirmPassword) { alert("所有字段都不能为空"); return; } if (newPassword !== confirmPassword) { alert("两次输入的新密码不一致"); return; } if (newPassword.length < 6) { alert("新密码长度不能少于6位"); return; } // 发送AJAX请求 $.ajax({ url: '/api/student/changePassword', type: 'PUT', contentType: 'application/json', data: JSON.stringify({ oldPassword: oldPassword, newPassword: newPassword }), success: function(response) { alert(response.message); if (response.code === 200) { $('#changePasswordForm')[0].reset(); // 清空表单 window.location.href = '/login.html'; // 强制重新登录 } }, error: function(xhr) { alert(`修改失败: ${xhr.responseJSON?.message || "网络异常"}`); } }); }); }); </script> </body> </html> 为什么修改密码时 原密码一直错误
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值