MD5加密实现注册登录系统

该博客详细介绍了如何利用MD5加密技术,结合Java和数据库构建一个安全的注册登录系统。涉及到的主要组件包括Main类、DBLink、IRowMapper、MD5Tool和PropertiesTool。同时,配置了db.properties和log4j.properties文件,确保数据连接和日志记录的正常运行。
摘要由CSDN通过智能技术生成

结构:

在这里插入图片描述

Main:

package com.jd.test;

import java.util.Scanner;
import java.util.UUID;

import com.jd.tool.MD5Tool;
import com.jd.tool.db.DBLink;

public class Main {
   

	public static void main(String[] args) {
   
		System.out.println("*********************************");
		System.out.println("*\t\t\t\t*");
		System.out.println("*\t欢迎使用注册登录系统\t*");
		System.out.println("*\t\t\t\t*");
		System.out.println("*********************************");
		while (true) {
   
			menu();
		}
	}

	static void menu() {
   
		System.out.println("1、注册");//用户名  密码  确认密码
		System.out.println("2、登录");//用户名和密码
		System.out.println("3、退出");//System.exit(0);
		System.out.println("请输入操作,以Enter键结束:");
		Scanner scanner = new Scanner(System.in);
		int option  = scanner.nextInt();
		DBLink dblink = new DBLink();
		
		switch (option) {
   
			case 1:{
   
				dblink.getConnection();
				System.out.println("请输入用户名:");
				String userName = scanner.next();
				System.out.println("请输入密码:");
				String password = scanner.next();
				System.out.println("请确认密码:");
				String repassword = scanner.next();
				String sql = "select id from user_info where user_name=?";
				if(dblink.exist(sql,userName)) {
   
					System.out.println("用户名已存在");
					return;
				}
				if(!password.equals(repassword)) {
   
					System.out.println("密码与确认密码不一致");
					return;
				}
				String id = UUID.randomUUID().toString();
				sql = "insert into user_info (id,user_name,password) values ('"+id+"',?,?)";
				password = new MD5Tool().encrypt(password);
				if(dblink.update(sql,userName,password)) {
   
					System.out.println("注册成功");
					return;
				}
				System.out
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值