Update
This commit is contained in:
1 parent
34f68b1fe9
commit
ba46ad52f6
9 files changed
+119
-144
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -71,4 +71,4 @@ public class CashierStatistics {
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,81 +4,68 @@ import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PasswordChange {
|
||||
static final String DBURL = "jdbc:mysql://localhost:3306/xiaoshou?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
|
||||
private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String DBURL = "jdbc:mysql://localhost:3306/xiaoshou?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
Connection conn = null;
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class.forName(DBDRIVER);
|
||||
Connection conn = DriverManager.getConnection(DBURL);
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
conn = DriverManager.getConnection(DBURL);
|
||||
System.out.print("请输入用户名:");
|
||||
String username = scanner.nextLine();
|
||||
String checkUserSql = "SELECT xingming FROM t_yong WHERE yonghuming=?";
|
||||
pstmt = conn.prepareStatement(checkUserSql);
|
||||
pstmt.setString(1, username);
|
||||
rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
System.out.println("该用户不存在,请重新输入");
|
||||
return;
|
||||
}
|
||||
System.out.print("请输入当前用户的原密码:");
|
||||
String oldPassword = scanner.nextLine();
|
||||
String checkPasswordSql = "SELECT xingming FROM t_yong WHERE yonghuming=? AND mima=MD5(?)";
|
||||
pstmt = conn.prepareStatement(checkPasswordSql);
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, oldPassword);
|
||||
rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
System.out.println("原密码输入不正确,请重新输入");
|
||||
return;
|
||||
}
|
||||
String newPassword;
|
||||
while (true) {
|
||||
System.out.print("请设置新的密码:");
|
||||
newPassword = scanner.nextLine();
|
||||
if (!isPasswordComplex(newPassword))
|
||||
System.out.println("您的密码不符合复杂性要求(密码长度不少于6个字符,至少有一个小写字母,至少有一个大写字母,至少一个数字),请重新输入:");
|
||||
else
|
||||
break;
|
||||
}
|
||||
System.out.print("请输入确认密码:");
|
||||
String confirmPassword = scanner.nextLine();
|
||||
if (!newPassword.equals(confirmPassword)) {
|
||||
System.out.println("两次输入的密码必须一致,请重新输入确认密码:");
|
||||
return;
|
||||
}
|
||||
String updatePasswordSql = "UPDATE t_yong SET mima=? WHERE yonghuming=?";
|
||||
pstmt = conn.prepareStatement(updatePasswordSql);
|
||||
pstmt.setString(1, Encrypt.MD5(newPassword));
|
||||
pstmt.setString(2, username);
|
||||
int result = pstmt.executeUpdate();
|
||||
if (result > 0)
|
||||
System.out.println("您已成功修改密码,请谨记");
|
||||
else
|
||||
System.out.println("密码修改失败,请重试");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("请输入用户名:");
|
||||
String username = scanner.nextLine();
|
||||
String checkUserSql = "SELECT xingming FROM t_yong WHERE yonghuming=?";
|
||||
pstmt = conn.prepareStatement(checkUserSql);
|
||||
pstmt.setString(1, username);
|
||||
rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
System.out.println("该用户不存在,请重新输入");
|
||||
return;
|
||||
}
|
||||
System.out.print("请输入当前用户的原密码:");
|
||||
String oldPassword = scanner.nextLine();
|
||||
String checkPasswordSql = "SELECT xingming FROM t_yong WHERE yonghuming=? AND mima=MD5(?)";
|
||||
pstmt = conn.prepareStatement(checkPasswordSql);
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, oldPassword);
|
||||
rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
System.out.println("原密码输入不正确,请重新输入");
|
||||
return;
|
||||
}
|
||||
String newPassword;
|
||||
while (true) {
|
||||
System.out.print("请设置新的密码:");
|
||||
newPassword = scanner.nextLine();
|
||||
if (!isPasswordComplex(newPassword))
|
||||
System.out.println("您的密码不符合复杂性要求(密码长度不少于6个字符,至少有一个小写字母,至少有一个大写字母,至少一个数字),请重新输入:");
|
||||
else
|
||||
break;
|
||||
}
|
||||
System.out.print("请输入确认密码:");
|
||||
String confirmPassword = scanner.nextLine();
|
||||
if (!newPassword.equals(confirmPassword)) {
|
||||
System.out.println("两次输入的密码必须一致,请重新输入确认密码:");
|
||||
return;
|
||||
}
|
||||
String updatePasswordSql = "UPDATE t_yong SET mima=? WHERE yonghuming=?";
|
||||
pstmt = conn.prepareStatement(updatePasswordSql);
|
||||
pstmt.setString(1, Encrypt.MD5(newPassword));
|
||||
pstmt.setString(2, username);
|
||||
int result = pstmt.executeUpdate();
|
||||
if (result > 0)
|
||||
System.out.println("您已成功修改密码,请谨记");
|
||||
else
|
||||
System.out.println("密码修改失败,请重试");
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public static boolean isPasswordComplex(String password) {
|
||||
|
||||
@@ -74,4 +74,4 @@ public class PermissionJudgment {
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,37 +9,38 @@ import java.sql.SQLException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ProductAdditionAndInquiry {
|
||||
private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String DBURL = "jdbc:mysql://localhost:3306/xiaoshou?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class.forName(DBDRIVER);
|
||||
Connection conn = DriverManager.getConnection(DBURL);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int choice;
|
||||
try (Connection conn = DriverManager.getConnection(DBURL)) {
|
||||
do {
|
||||
System.out.println("===超市商品管理维护====");
|
||||
System.out.println("1、输入商品");
|
||||
System.out.println("2、查询商品");
|
||||
System.out.println("3、退出");
|
||||
System.out.print("请选择(1-3):");
|
||||
choice = scanner.nextInt();
|
||||
scanner.nextLine();
|
||||
switch (choice) {
|
||||
case 1:
|
||||
addProduct(scanner, conn);
|
||||
break;
|
||||
case 2:
|
||||
queryProduct(scanner, conn);
|
||||
break;
|
||||
case 3:
|
||||
System.out.println("退出系统");
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效选择,请重新选择(1-3):");
|
||||
}
|
||||
} while (choice != 3);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
do {
|
||||
System.out.println("===超市商品管理维护====");
|
||||
System.out.println("1、输入商品");
|
||||
System.out.println("2、查询商品");
|
||||
System.out.println("3、退出");
|
||||
System.out.print("请选择(1-3):");
|
||||
choice = scanner.nextInt();
|
||||
scanner.nextLine();
|
||||
switch (choice) {
|
||||
case 1:
|
||||
addProduct(scanner, conn);
|
||||
break;
|
||||
case 2:
|
||||
queryProduct(scanner, conn);
|
||||
break;
|
||||
case 3:
|
||||
System.out.println("退出系统");
|
||||
break;
|
||||
default:
|
||||
System.out.println("无效选择,请重新选择(1-3):");
|
||||
}
|
||||
} while (choice != 3);
|
||||
conn.close();
|
||||
}
|
||||
|
||||
private static void addProduct(Scanner scanner, Connection conn) throws SQLException {
|
||||
|
||||
@@ -79,4 +79,4 @@ public class ProductModificationAndDeletion {
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,63 +4,50 @@ import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UserLogin {
|
||||
static final String DBURL = "jdbc:mysql://localhost:3306/xiaoshou?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
|
||||
private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String DBURL = "jdbc:mysql://localhost:3306/xiaoshou?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
Connection conn = null;
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class.forName(DBDRIVER);
|
||||
Connection conn = DriverManager.getConnection(DBURL);
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
conn = DriverManager.getConnection(DBURL);
|
||||
int attempts = 0;
|
||||
boolean loginSuccess = false;
|
||||
while (attempts < 3 && !loginSuccess) {
|
||||
System.out.println("欢迎使用阳光超市收银系统,请登陆");
|
||||
System.out.print("请输入用户名: ");
|
||||
String username = scanner.nextLine();
|
||||
System.out.print("请输入密码: ");
|
||||
String password = scanner.nextLine();
|
||||
String sql = "SELECT xingming FROM t_yong WHERE yonghuming=? AND mima=?";
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, Encrypt.MD5(password));
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
loginSuccess = true;
|
||||
String xingming = rs.getString("xingming");
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
|
||||
String currentTime = formatter.format(new Date());
|
||||
System.out.println("欢迎使用阳光超市收银系统");
|
||||
System.out.println("当前收银员:" + xingming);
|
||||
System.out.println("当前时间:" + currentTime);
|
||||
} else {
|
||||
System.out.println("用户名或密码不正确,请重新输入");
|
||||
attempts++;
|
||||
}
|
||||
}
|
||||
if (!loginSuccess)
|
||||
System.out.println("最多只能尝试3次");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int attempts = 0;
|
||||
boolean loginSuccess = false;
|
||||
while (attempts < 3 && !loginSuccess) {
|
||||
System.out.println("欢迎使用阳光超市收银系统,请登陆");
|
||||
System.out.print("请输入用户名: ");
|
||||
String username = scanner.nextLine();
|
||||
System.out.print("请输入密码: ");
|
||||
String password = scanner.nextLine();
|
||||
String sql = "SELECT xingming FROM t_yong WHERE yonghuming=? AND mima=?";
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setString(1, username);
|
||||
pstmt.setString(2, Encrypt.MD5(password));
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
loginSuccess = true;
|
||||
String xingming = rs.getString("xingming");
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
|
||||
String currentTime = formatter.format(new Date());
|
||||
System.out.println("欢迎使用阳光超市收银系统");
|
||||
System.out.println("当前收银员:" + xingming);
|
||||
System.out.println("当前时间:" + currentTime);
|
||||
} else {
|
||||
System.out.println("用户名或密码不正确,请重新输入");
|
||||
attempts++;
|
||||
}
|
||||
}
|
||||
if (!loginSuccess)
|
||||
System.out.println("最多只能尝试3次");
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user