怎样用java设置帐号和密码

Python040

怎样用java设置帐号和密码,第1张

public class User{

//定义私有属性 用户名密码

private String userName

private String password

public User(String userName,String password){

this.userName=userName

this.password=password

}

//私有属性的set get 方法

public void setUserName(String userName){

this.userName=userName

}

public void setPassword(String password){

this.password=password

}

public String getUserName(){

return this.userName

}

public String getPassword(){

return this.password

}

//用来判断用户名和密码是否正确

public boolean panDuan(){

if("用户名".equals(this.userName)&&"密码".equals(this.password)){

System.out.println("登入成功!")

return true

}else{

System.out.println("登入失败!")

return false

}

}

public static void main (String[] args){

System.out.println("请输入用户名:")

Scanner sc=new Scanner(System.in)

String userName=sc.nextLine()

System.out.println("请输入密码:")

String password=sc.nextLine()

User u=new User(userName,password)

u.panDuan()

}

}

密码是否一致最好是在前端先判断,后端进行再次检验。要判断当前密码是否正确,必须把用户的账号一起传上去,然后取出改用户,拿旧密码与当前密码进行判断。2次输入的新密码一致,可以用password1.equals(password2)