JAVA实现用户注册,登录,修改密码
JAVA实现⽤户注册,登录,修改密码class
import java.util.Arrays;
import java.util.Scanner;
public class User {
String name;
String password;
String sex ;
int age ;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
绥宁县return password;
}
public void setPassword(String password) {
this.password = password;
如何去爱
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public User[] shuzu(User[] users) {  //初始化数组,预存2⼈
users[0].name = "qqq";
users[0].password = "123";
users[1].name = "bbb";
users[1].password = "456";
for (int i = 0; i < users.length; i++) {
System.out.println(users[i].name+" "+users[i].password);致我们终将逝去的青春 豆瓣
}
return users;
}
//______________________注册__________________________________
public User[] register(String newn,String newp,User[] users){
users= pyOf(users, users.length+1);//数组扩容+1
User q = new User() ;
//        System.out.println(users.length); //输出新数组长度,辅助校验数组扩容
int a = 0 ;
for (int i = 0; i < users.length-1; i++) { //校验⽤户名是否重复,重复 a+1
if(users[i].name.equals(newn) ){
a++;
}
}
if(a == 0){//a=0.⽤户名不重复,赋值
users[users.length-1] = q ;//新建对象存⼊数组最后⼀个位置
users[users.length-1].name = newn;
users[users.length-1].password = newp;
System.out.println("注册成功");
}else{ // ⽤户名重复,提⽰
System.out.println("⽤户名重复");
}
//        for (int i = 0; i < users.length; i++) { //输出现有⽤户名,辅助校验
//        System.out.println(users[i].name);
//        }
return users;//返回数组
}
/
/______________________登录__________________________________
int flag;// 辅助循环判定
public void login(String newn,String newp,User[] users){
for (int i = 0; i < users.length; i++) {//循环遍历数组
System.out.println(users[i].name+"标记"+i+"标记"+users[i].password);//遍历输出现在数组
if(newn.equals(users[i].name) && newp.equals(users[i].password) ){
flag = 0; //同⼀下标的对象的⽤户名和密码与输⼊的⽤户名和密码都⼀样,flag赋值0
break;//退出循环
}else{
flag =1;//同⼀下标的对象的⽤户名和密码与输⼊的⽤户名和密码不⼀样,flag赋值0,说明输⼊的⽤户名和密码有问题
}
}
//        System.out.println(newn + newp);
if(flag == 0){  // 给出系统提⽰
System.out.println("登录成功");
}else{
麦哲伦的故事System.out.println("⽤户名或密码错误,登录失败");
}
}
//________________________________修改密码——————————————————————————————————public User[] change(String oldn,String oldm,User[] users) {
int a = 0 ;
for (int i = 0; i < users.length; i++) {//循环遍历数组,校验输⼊的⽤户名是否存在
if(oldn.equals(users[i].name)){
a = i;
flag = 0;
}else{
flag = 1 ;
}
}
if(flag == 0){//输⼊的⽤户名存在,输⼊的新密码替换旧密码
users[a].password = oldm;
System.out.println("密码修改成功");
System.out.println("⽤户名:"+users[a].name +"  "+"新密码"+users[a].password);
}else{//输⼊的⽤户名不存在,提⽰输⼊有误
System.out.println("输⼊的⽤户名未查询到");
}
return users;//返回新数组
}
}
demo
import java.util.Arrays;
import java.util.Scanner;
public class Demo1{//_____________________⽤户名密码————————————————————
public static void main(String[] args) {
User us = new User();
User us1 = new User();
User us2 = new User();
User[] users = {us1,us2};
us.shuzu( users);//初始化数组
for (int i = 1; i > 0; i++) {    //循环实现登录注册
System.out.println("请选择操作:1注册,2登录    3修改密码");
Scanner sc = new Scanner(System.in);
String num = sc.next();
if(num.equals("1")){  // 注册功能
System.out.println("_________注册__________");
System.out.println("请创建⽤户名");
us.());
System.out.println("请创建密码");
us.());
//        System.out.Name());
users = us.Name(),us.getPassword(), users);
}else if(num.equals("2")){ // 登录功能
System.out.println("__________登录_________");
System.out.println("请输⼊⽤户名");
草原歌曲专辑String newn = sc.next();
System.out.println("请输⼊密码");
String newp = sc.next();
us.login(newn, newp, users);
}else if(num.equals("3")){ //修改密码
System.out.println("__________修改密码_________");
System.out.println("请输⼊旧⽤户名");
us.());
System.out.println("请输⼊新的密码");
us.());
users = us.Name(), us.getPassword(), users);
}
else{  //输⼊值有误,提⽰
System.out.println("输⼊的值有误");
}
}
}
}高二化学教学计划

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。