[ Java / Database ] 비밀번호 변경 클래스 만들기

2024. 2. 3. 18:25· 프로젝트로 연습하기/└ Project1_프로그램의 구성 이해

환경 : Eclipse, DBeaver

 

[ UserPasswordChanging.java ]

- 비밀번호를 바꿀 아이디를 입력받고, 해당 아이디의 현재 비밀번호를 입력받는다.

- 현재 비밀번호가 일치하면 비밀번호를 바꿀 수 있도록 구현하였다.

package userEx.app;

import java.util.Scanner;

import userEx.dao.UserExDao;
import userEx.dto.UserExDto;

public class UserPasswordChanging {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		//가장 중요한 건 아이디와 바꿀 비밀번호를 알아야 한다
		UserExDto dto = new UserExDto();
		System.out.print("아이디 : ");
		dto.setUserId(sc.nextLine());
		System.out.print("현재 비밀번호 : ");
		String currentPw = sc.nextLine();
		System.out.print("바꿀 비밀번호 : ");
		dto.setUserPassword(sc.nextLine());

		sc.close();
		
		//현재 비밀번호 판정 추가
		UserExDao dao = new UserExDao();
		UserExDto find = dao.selectOne(dto.getUserId());
		if(find != null && find.getUserPassword().equals(currentPw) ) {
			//업데이트
			dao.updateUserPw(dto);
			System.out.println("비밀번호 변경 완료");
		} else {
			System.out.println("정보가 일치하지 않습니다");
		}
		
	}
}

 

 

출력 결과

 

 

 

개인 공부 기록용입니다:)

728x90