| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 538 人关注过本帖
标题:求助! 验证帐号,密码的问题!
只看楼主 加入收藏
flying2533
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-18
收藏
 问题点数:0 回复次数:2 
求助! 验证帐号,密码的问题!

我做的一个修改密码的界面,在验证原密码时总是错误!高手帮忙看下原因...谢谢





package netbar;

import java.awt.*;

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class updatepasswordview extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JPasswordField jPasswordField2 = new JPasswordField();
JPasswordField jPasswordField3 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel5 = new JLabel();
public updatepasswordview() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("网吧计费管理系统—密码修改");
jLabel1.setText(" 用户帐号:");
jLabel1.setBounds(new Rectangle(66, 36, 80, 25));
jLabel2.setText(" 原密码:");
jLabel2.setBounds(new Rectangle(66, 72, 80, 25));
jLabel3.setText(" 新密码:");
jLabel3.setBounds(new Rectangle(66, 107, 80, 25));
jLabel4.setText("重复新密码:");
jLabel4.setBounds(new Rectangle(66, 142, 80, 25));
jTextField1.setFont(new java.awt.Font("宋体", Font.PLAIN, 13));
jTextField1.setBounds(new Rectangle(162, 36, 160, 25));
jPasswordField1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jPasswordField1.setBounds(new Rectangle(162, 72, 160, 25));
jPasswordField2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jPasswordField2.setBounds(new Rectangle(162, 107, 160, 25));
jPasswordField3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
jPasswordField3.setBounds(new Rectangle(163, 142, 159, 25));
jButton1.setBackground(UIManager.getColor("window"));
jButton1.setBounds(new Rectangle(76, 211, 85, 25));
jButton1.setText("确 认");
jButton1.addActionListener(new
updatepasswordview_jButton1_actionAdapter(this));
jButton2.setBackground(UIManager.getColor("window"));
jButton2.setBounds(new Rectangle(223, 211, 85, 25));
jButton2.setText("重 置");
jButton2.addActionListener(new
updatepasswordview_jButton2_actionAdapter(this));
jLabel5.setForeground(Color.red);
jLabel5.setBounds(new Rectangle(66, 180, 256, 25));
contentPane.add(jLabel1);
contentPane.add(jTextField1);
contentPane.add(jPasswordField1);
contentPane.add(jLabel2);
contentPane.add(jPasswordField2);
contentPane.add(jLabel3);
contentPane.add(jPasswordField3);
contentPane.add(jLabel4);
contentPane.add(jButton2);
contentPane.add(jButton1);
contentPane.add(jLabel5);
}

public void jButton2_actionPerformed(ActionEvent e) {
jTextField1.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
jPasswordField3.setText("");
jLabel5.setText("");
jTextField1.requestFocus();
}

public void jButton1_actionPerformed(ActionEvent e) {
NetBarUser nbu = new NetBarUser();
nbu.setNBUN(jTextField1.getText());
nbu.setNBP(new String(jPasswordField1.getPassword()));
if (jTextField1.getText().length() == 0) {
jLabel5.setText("帐号不能为空!");
jTextField1.requestFocus();
} else if (jPasswordField1.getPassword().length == 0) {
jLabel5.setText("密码不能为空!");
jPasswordField1.requestFocus();
} else if (jPasswordField2.getPassword().length == 0 ||
jPasswordField3.getPassword().length == 0) {
jLabel5.setText("新密码不能为空!");
jPasswordField2.requestFocus();
} else if (jPasswordField2.getPassword().length<6) {
jLabel5.setText("密码长度不得少于6位,请重新输入!");
jPasswordField2.requestFocus();
} else if (!new String(jPasswordField2.getPassword()).equals(new String(
jPasswordField3.getPassword()))) {
jLabel5.setText("两次输入的新密码不一致,请重新输入!");
jPasswordField2.setText("");
jPasswordField3.setText("");
jPasswordField2.requestFocus();
} else if (!sqldemo.NetBarUse(nbu)) {
jLabel5.setText("帐号或密码错误,请重新输入!");
} else {
//NetBarUser nbu_1 = new NetBarUser();
// nbu_1.setNBP(new String(jPasswordField2.getPassword()));
// nbu_1.setNBUN(jTextField1.getText());
//sqldemo.updatepassword(nbu_1);
this.setVisible(false);
dengluview dlv = new dengluview();
dlv.setVisible(true);
dlv.jLabel4.setText("");
dlv.jLabel3.setText(" 密码修改成功,请登陆!");
}
}
}


class updatepasswordview_jButton1_actionAdapter implements ActionListener {
private updatepasswordview adaptee;
updatepasswordview_jButton1_actionAdapter(updatepasswordview adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}


class updatepasswordview_jButton2_actionAdapter implements ActionListener {
private updatepasswordview adaptee;
updatepasswordview_jButton2_actionAdapter(updatepasswordview adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}

---------------------------------------------------------------------------------------------



package netbar;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class NetBarUser {
String NBUN;
String NBP;
String NBN;
public void setNBUN(String NBUN) {
this.NBUN = NBUN;
}

public String getNBUN() {
return NBUN;
}

public void setNBP(String NBP) {
this.NBP = NBP;
}

public String getNBP() {
return NBP;
}

public void setNBN(String NBN) {
this.NBN = NBN;
}

public String getNBN() {
return NBN;
}
}


----------------------------------------------------------------------------------------------------


package netbar;

import java.sql.*;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/


//数据库连接
class getconn {
Connection con;
public Connection getconn() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:NetBar", "sa", "");
} catch (Exception ex) {
}
return con;
}
}


--------------------------------------------------------------------------------------------


package netbar;

import java.sql.*;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
class sqldemo{
public static boolean NetBarUse(NetBarUser nbu) {
boolean bl = true;
Connection con = new getconn().getconn();
String sql =
"select UserName,Password from NetBarinfo";
try {
PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
if (nbu.getNBUN().equals(rs.getString("UserName")) &&
nbu.getNBP().equals(rs.getString("Password"))) {
bl = true;
break;
} else {
bl = false;
break;
}
}
rs.close();
pst.close();
con.close();
} catch (Exception ex) {
}
return bl;
}

}



搜索更多相关主题的帖子: 帐号 密码 验证 
2007-06-21 10:33
wolfme
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-6-28
收藏
得分:0 

哇塞 ,,,看不懂。郁闷。。俺是初学者

2007-06-23 15:32
hyfz_825
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2007-5-2
收藏
得分:0 
   越看越不能明白呀!咋我和写的不一样呢?现在都怀疑自己了。

爲明天而奮鬥!!!
2007-06-23 23:02
快速回复:求助! 验证帐号,密码的问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028481 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved