「java登录注册」Java登录注册

博主:adminadmin 2022-11-27 06:10:06 46

今天给各位分享java登录注册的知识,其中也会对Java登录注册进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java使用面向对象写一个登录注册查询的功能

import java.util.Scanner;/**

* 采用面向对象的方式 写一个登录系统

* @author Administrator

*

*///用户信息class UserInfo{ public static String[] user = new String[10]; public static String[] passwd = new String[10];

public UserInfo() { this.user[0] = "test"; this.passwd[0] ="123456";

}

}//找回密码class ZhaoHui extends UserInfo{ public static void zhaohui() {

Scanner s = new Scanner(System.in);

System.out.println("请输入你要找回的用户名:");

String zname = s.nextLine(); for(int i=0;i2;i++) { if(user[i].equals(zname)) {

Scanner ss = new Scanner(System.in);

System.out.println("恭喜你!成功找回密码,请输入:"+"'张哥最帅'"+" 查看密码");

String zgzs = ss.nextLine();

if("张哥最帅".equals(zgzs)) {

System.out.println(passwd[i]);

}else {

System.out.println("请输正确!");

}

}else if(user[i]!=zname){

System.out.println("用户名不存在!"); return;

}

break;

}

}

}//修改密码 class XiuGai extends UserInfo{ public static void xiugai() {

Scanner s =new Scanner(System.in);

System.out.println("请输入您要修改的密码:");

String xpasswd = s.nextLine(); for(int i=0;i2;i++) {

passwd[i] = xpasswd; if(xpasswd.equals(passwd[i])) {

System.out.println("恭喜你,修改成功!"); break;

}else {

System.out.println("修改密码失败"); break;

}

}

}

}//查询用户class ChaXun extends UserInfo{

public static void select() { for(int i=0;i2;i++) {

System.out.println("当前用户:"+user[i] +"\n"+ "当前密码:"+passwd[i] );

i++; break;

}

}

}//注册class ZhuCe extends UserInfo{

public static void regist() {

Scanner ss = new Scanner(System.in);

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

String suser = ss.nextLine();

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

String spasswd = ss.nextLine();

for(int i=0;iuser.length;i++) {

user[i] = suser;

passwd[i] = spasswd;

System.out.println("注册成功!"); break;

}

}

}//登录class Loginc extends UserInfo{

public static void login() { int flag = 1;

Scanner scanner = new Scanner(System.in);

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

String users = scanner.nextLine();

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

String passwds = scanner.nextLine();

for(int i=0;iUserInfo.user.length;i++) { if(user[i].equals(users) passwd[i].equals(passwds)) {

System.out.println("登陆成功!"); break;

}

System.out.println("登陆失败!"); break;

}

}

}//主界面class ZhuJieMian{ public static void Start() {

Loginc Loginc = new Loginc();

ZhuCe ZhuCe = new ZhuCe();

ChaXun ChaXun = new ChaXun();

XiuGai XiuGai = new XiuGai();

ZhaoHui ZhaoHui = new ZhaoHui();

Scanner s = new Scanner(System.in); while(true) {

System.out.println("|"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+"\t"+"|");

System.out.println("|"+"\t" + "测试用户名:test 测试密码:123456" + "\t"+ "\t"+ "\t"+ "\t"+"|");

System.out.println("|" + "\t"+ "请输入[1-5]进行操作 1.登录|2.注册|3.查询当前用户|4.修改密码|5.找回密码 " + "\t"+"|");

System.out.print("请输入:"); int temp = s.nextInt();

switch(temp) { case 1:Loginc.login(); break; case 2:ZhuCe.regist();; break; case 3:ChaXun.select();; break; case 4:XiuGai.xiugai();; break; case 5:ZhaoHui.zhaohui();; break; default:System.out.println("错误!请重写输入正确的数字进行操作!");

}

}

}

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

ZhuJieMian zjm = new ZhuJieMian();

zjm.Start();

}

}

用java编程实现用户注册并进行登录操作

String username = "",password = "",passwordagain = ""; // 定义用户名和密码

将该变量等于为全局变量 或局部变量即可

java语言实现用户注册和登录

//这个是我写的,里面有连接数据库的部分。你可以拿去参考一下

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.sql.*;

class LoginFrm extends JFrame implements ActionListener// throws Exception

{

JLabel lbl1 = new JLabel("用户名:");

JLabel lbl2 = new JLabel("密码:");

JTextField txt = new JTextField(5);

JPasswordField pf = new JPasswordField();

JButton btn1 = new JButton("确定");

JButton btn2 = new JButton("取消");

public LoginFrm() {

this.setTitle("登陆");

JPanel jp = (JPanel) this.getContentPane();

jp.setLayout(new GridLayout(3, 2, 5, 5));

jp.add(lbl1);

jp.add(txt);

jp.add(lbl2);

jp.add(pf);

jp.add(btn1);

jp.add(btn2);

btn1.addActionListener(this);

btn2.addActionListener(this);

}

public void actionPerformed(ActionEvent ae) {

if (ae.getSource() == btn1) {

try {

Class.forName("com.mysql.jdbc.Driver");// mysql数据库

Connection con = DriverManager.getConnection(

"jdbc:mysql://localhost/Car_zl", "root", "1");// 数据库名为Car_zl,密码为1

System.out.println("com : "+ con);

Statement cmd = con.createStatement();

String sql = "select * from user where User_ID='"

+ txt.getText() + "' and User_ps='"

+ pf.getText() + "'" ;

ResultSet rs = cmd

.executeQuery(sql);// 表名为user,user_ID和User_ps是存放用户名和密码的字段名

if (rs.next()) {

JOptionPane.showMessageDialog(null, "登陆成功!");

} else

JOptionPane.showMessageDialog(null, "用户名或密码错误!");

} catch (Exception ex) {

}

if (ae.getSource() == btn2) {

System.out.println("1111111111111");

//txt.setText("");

//pf.setText("");

System.exit(0);

}

}

}

public static void main(String arg[]) {

JFrame.setDefaultLookAndFeelDecorated(true);

LoginFrm frm = new LoginFrm();

frm.setSize(400, 200);

frm.setVisible(true);

}

}

性能测试中如何使用java批量注册登录账户

性能测试中示例代码使用java批量注册登录账户。

性能测试过程中所需的测试数据,以登录为例,为了更真实的模 批量读取注册。

Java登录注册功能实现代码解析,文中通示例代码,每个用户信息都是唯一的,所以可以借助Set的特性来操作用户信息的存放。

java登录注册的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Java登录注册、java登录注册的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-27,除非注明,否则均为首码项目网原创文章,转载请注明出处。