java代码实现密码验证 java输入密码验证-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

java代码实现密码验证 java输入密码验证

JAVA 设计swing登录界面验证用户名密码

应用的还是web的啊..

为湘乡等地区用户提供了全套网页设计制作服务,及湘乡网站建设行业解决方案。主营业务为成都网站制作、网站设计、湘乡网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

我给你写了个应用的哈

你在C盘建个test.txt文件

里面写

username:用户名(这里可以随便写哈)

password:同上哈

注意是要换行的哦。。

比如

username:tiger

password:tiger

然后你建个Login的类

然后把下面的代码弄进去

运行就是了

注意登陆的时候你文件里面设定的什么用户名和密码就输入什么哈

输入错误就会提示输入错误的

import java.io.BufferedReader;

import java.io.FileReader;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

/**

*

* @author thinkpad

*/

public class Login extends javax.swing.JFrame {

/** Creates new form Login */

private static String username;

private static String password;

public Login() {

initComponents();

try {

BufferedReader br = new BufferedReader(new FileReader("C:\\test.txt"));

username = br.readLine().split("\\:")[1];

password = br.readLine().split("\\:")[1];

System.out.println(username + password);

} catch(Exception e) {

e.printStackTrace();

}

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

// editor-fold defaultstate="collapsed" desc="Generated Code"

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jTextField1 = new javax.swing.JTextField();

jPasswordField1 = new javax.swing.JPasswordField();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N

jLabel1.setText("Login");

jLabel2.setText("Username:");

jLabel3.setText("Password:");

jTextField1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jTextField1ActionPerformed(evt);

}

});

jPasswordField1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jPasswordField1ActionPerformed(evt);

}

});

jButton1.setText("Login");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

}

});

jButton2.setText("Reset");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

}

});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(28, 28, 28)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel2)

.addComponent(jLabel3))

.addGap(33, 33, 33)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)

.addComponent(jPasswordField1, 0, 0, Short.MAX_VALUE)

.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jButton1)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jButton2))))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGap(101, 101, 101)

.addComponent(jLabel1)))

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel1)

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel2))

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel3))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jButton1)

.addComponent(jButton2)))

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addContainerGap())

);

pack();

}// /editor-fold

private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

this.jTextField1.setText("");

this.jPasswordField1.setText("");

}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

String inputUsername = this.jTextField1.getText();

String inputPassword = String.valueOf(this.jPasswordField1.getPassword());

if(inputUsername.equals(username) inputPassword.equals(password)) {

JOptionPane.showMessageDialog(this, "Login success!");

} else {

JOptionPane.showMessageDialog(this, "Login failed!");

}

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

JFrame.setDefaultLookAndFeelDecorated(true);

Login login = new Login();

login.setVisible(true);

login.setLocationRelativeTo(null);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JPanel jPanel1;

private javax.swing.JPasswordField jPasswordField1;

private javax.swing.JTextField jTextField1;

// End of variables declaration

}

在java里添加用户注册密码校验,和重复登录的密码确认,速求

代码已写完,但是由于字数问题无法粘贴上来。把你邮箱给我,我给你发过去。

java 请教一下用户名密码校验的问题

你这里没有用文件也没有用数据库,注册的账号只能用一次,当程序关闭后,这个账号的数据就没有了。

建议使用文件或者数据库保存注册了的账号和密码。如果不是很清楚这两个东西,建议再向后面学习。

JAVA 用户密码修改验证模块,旧密码,新密码,确认密码

//Js中的验证

//检查旧密码

function checkOldPassword(){

var hasErr = false;

var form = document.getElementById("form");

//检查旧密码

if(form.oldpass.value.length  1){

document.getElementById("errPwd").innerHTML = "请输入您现在的密码";

document.getElementById("errPwd").style.display = "inline-block";

hasErr = true;

}else{

document.getElementById("errPwd").style.display = "none";

}

return hasErr;

}

//检查新密码

function checkNewPassword(){

var form = document.getElementById("form");

var errNewPwdMsg = "";

var hasErr = false;

if(form.password.value.length  1){

errNewPwdMsg = "请输入新密码";

}else if ( form.password.value == getSsn(form.username.value) || form.password.value == form.username.value){

errNewPwdMsg = "密码和用户名不能相同";

}else if( charAllSame(form.password.value) ){

errNewPwdMsg = "您的密码过于简单";

}else if(strlen(form.password.value)6 || strlen(form.password.value)16 ){

errNewPwdMsg = "正确的密码长度为6-16位";

}else if(strlen2(form.password.value)){

errNewPwdMsg = "新密码包含了非法字符";

}

else if (form.oldpass.value == form.password.value){

errNewPwdMsg = "新旧密码不能相同";

}

if(errNewPwdMsg != ""){

document.getElementById("errNewPwd").innerHTML = errNewPwdMsg;

document.getElementById("errNewPwd").style.display = "inline-block";

hasErr = true;

}else{

document.getElementById("errNewPwd").style.display = "none";

}

return hasErr;

}

//检查新密码确认

function checkNewPasswordConfirm(){

var form = document.getElementById("form");

var hasErr = false;

if(form.confirmPassword.value != form.password.value ){

document.getElementById("errNewConfirmPwd").innerHTML = "您两次输入的新密码不一致,请确认";

document.getElementById("errNewConfirmPwd").style.display = "inline-block";

hasErr  = true;

}else{

document.getElementById("errNewConfirmPwd").style.display = "none";

}

return hasErr;

}

function checkdata(form) {

//检查旧密码

if(checkOldPassword()){

form.oldpass.focus();

return false;

}

//检查新密码

if(checkNewPassword()){

form.password.focus();

return false;

}

//检查新密码确认

if(checkNewPasswordConfirm()){

form.confirmPassword.focus();

return false;

}

JAVA 我要验证密码是否一致怎么写 return 啊

public boolean register_user(int pass){

boolean flag=true; //在此处定义变量

do {

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

String na = scanner.next();

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

String pas = scanner.next();

System.out.print("请再次输入密码");

String pa = scanner.next();

if (pa.equals(pas)){

System.out.println("注册成功你的账号为" + na + "你的密码为" + pa);

} else {

System.out.println("注册失败你2才输入的密码不一致,请重新输入");

flag=false;//如果失败改变标量的值

}

} while (!flag);

不需要return吧。。。

JAVA初学:关于密码验证的问题?

import java.awt.*;

import java.awt.event.*;

public class TestPassword {

public static void main(String[]args) {

MyTestFrame mf = new MyTestFrame("密码输入");

}

}

class MyTestFrame extends Frame {

Button b = new Button("确认");

TextField tf = new TextField(15);

public MyTestFrame(String str){

super(str);

tf.setEchoChar('*');

Panel p = new Panel();

p.setBackground(Color.BLACK);

b.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String str = tf.getText();

// System.out.println(str);

if(str.length()8) {

System.out.println("输入不能少于八位");

tf.setText("");

}

else {

if(str.matches("\\d*")) {

System.out.println("密码强度低 ");

}

if(str.matches("[a-z0-9]*")){

System.out.println("密码强度中 ");

}

if(str.matches("[a-zA-Z0-9]*")) {

System.out.println("密码强度高");

}

}

}

});

this.setLayout(new BorderLayout());

p.add(tf);

this.add(b,BorderLayout.EAST);

this.add(p,BorderLayout.CENTER);

pack();

this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

}

}

可费劲了 把课本又翻了一遍,正则表达式又复习了一下,gui也用上了


网站名称:java代码实现密码验证 java输入密码验证
URL链接:http://kswsj.cn/article/hhjpoh.html

其他资讯