验证简单登录系统上的多个用户

huangapple 未分类评论47阅读模式
英文:

Verifying Multiple users on a Simple Login System

问题

使用.txt文件作为数据库,文件中有两个用户,但此代码只能读取其中一个用户,另一个用户不能读取。我正在尝试使这两个用户都能正常工作。

try {
    FileReader fr = new FileReader("C:\\Users\\KIDS\\Desktop\\Marvels\\LoginCred\\Employeelogin.txt");
    BufferedReader br = new BufferedReader(fr);
    // 读取文本内容
    String usernameholder = br.readLine().substring(9);
    String passwordholder = br.readLine().substring(9);
    if(usernameid.getText().equals(usernameholder) && passwordid.getText().equals(passwordholder)) {
        JOptionPane.showMessageDialog(null, "授权访问!");
    }
    else{
        JOptionPane.showMessageDialog(null, "用户名/密码错误");
    }
}
catch(Exception e) {
    JOptionPane.showMessageDialog(null, "错误");
}

以下是用户信息:

插入图片描述

英文:

Im using .txt file as a database and there are 2 users in this file but this code can read only 1 user and the other cannot. im trying that the both of users will work

  try {
    FileReader fr = new FileReader("C:\\Users\\KIDS\\Desktop\\Marvels\\LoginCred\\Employeelogin.txt");
    BufferedReader br = new BufferedReader(fr);
  //      READS THE TEXT
  String usernameholder = br.readLine().substring(9);
  String passwordholder = br.readLine().substring(9);
 if(usernameid.getText().equals(usernameholder)&& passwordid.getText().equals(passwordholder)) {
     JOptionPane.showMessageDialog(null,"Access Granted!");
 }
 else{
     JOptionPane.showMessageDialog(null, "Wrong Username/Password");
 }
}
catch(Exception e) {
    JOptionPane.showMessageDialog(null,"Error");
}

Here is the Users
enter image description here

huangapple
  • 本文由 发表于 2020年5月3日 12:45:45
  • 转载请务必保留本文链接:https://java.coder-hub.com/61569742.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定