「java判断密码强度」测试密码强度

博主:adminadmin 2022-11-27 23:32:08 69

今天给各位分享java判断密码强度的知识,其中也会对测试密码强度进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Java web 如何判断密码强度

密码字符串的组成形式。

比如,纯数字的强度就小于纯字母的强度,纯字母的就小于数字与字母组合的强度(这种是自己通过写简单的代码来判断,当然,也可以下载相应的插件,百度搜一下应该有很多的)。

这个可以在页面上用jquery的插件来实现,如果密码有你自己的必要规则,那么写成正则在页面或者后台进行校验都是可以的

java 密码强度问题,请高手作答下,见问题补充,悬赏10

public class Demo {

    public static Safelevel GetPwdSecurityLevel(String pPasswordStr) {

        Safelevel safelevel = Safelevel.VERY_WEAK;

        if (pPasswordStr == null) {

            return safelevel;

        }

        int grade = 0;

        int index = 0;

        char[] pPsdChars = pPasswordStr.toCharArray();

        int numIndex = 0;

        int sLetterIndex = 0;

        int lLetterIndex = 0;

        int symbolIndex = 0;

        for (char pPsdChar : pPsdChars) {

            int ascll = pPsdChar;

            /*

             * 数字 48-57 A-Z 65 - 90 a-z 97 - 122 !"#$%'()*+,-./ (ASCII码:33~47)

             * :;=?@ (ASCII码:58~64) [\]^_` (ASCII码:91~96) {|}~

             * (ASCII码:123~126)

             */

            if (ascll = 48  ascll = 57) {

                numIndex++;

            } else if (ascll = 65  ascll = 90) {

                lLetterIndex++;

            } else if (ascll = 97  ascll = 122) {

                sLetterIndex++;

            } else if ((ascll = 33  ascll = 47)

                    || (ascll = 58  ascll = 64)

                    || (ascll = 91  ascll = 96)

                    || (ascll = 123  ascll = 126)) {

                symbolIndex++;

            }

        }

        /*

         * 一、密码长度: 5 分: 小于等于 4 个字符 10 分: 5 到 7 字符 25 分: 大于等于 8 个字符

         */

        if (pPsdChars.length = 4) {

            index = 5;

        } else if (pPsdChars.length = 7) {

            index = 10;

        } else {

            index = 25;

        }

        grade += index;

        /*

         * 二、字母: 0 分: 没有字母 10 分: 全都是小(大)写字母 20 分: 大小写混合字母

         */

        if (lLetterIndex == 0  sLetterIndex == 0) {

            index = 0;

        } else if (lLetterIndex != 0  sLetterIndex != 0) {

            index = 20;

        } else {

            index = 10;

        }

        grade += index;

        /*

         * 三、数字: 0 分: 没有数字 10 分: 1 个数字 20 分: 大于 1 个数字

         */

        if (numIndex == 0) {

            index = 0;

        } else if (numIndex == 1) {

            index = 10;

        } else {

            index = 20;

        }

        grade += index;

        /*

         * 四、符号: 0 分: 没有符号 10 分: 1 个符号 25 分: 大于 1 个符号

         */

        if (symbolIndex == 0) {

            index = 0;

        } else if (symbolIndex == 1) {

            index = 10;

        } else {

            index = 25;

        }

        grade += index;

        /*

         * 五、奖励: 2 分: 字母和数字 3 分: 字母、数字和符号 5 分: 大小写字母、数字和符号

         */

        if ((sLetterIndex != 0 || lLetterIndex != 0)  numIndex != 0) {

            index = 2;

        } else if ((sLetterIndex != 0 || lLetterIndex != 0)  numIndex != 0

                 symbolIndex != 0) {

            index = 3;

        } else if (sLetterIndex != 0  lLetterIndex != 0  numIndex != 0

                 symbolIndex != 0) {

            index = 5;

        }

        grade += index;

        

        /*

         * 最后的评分标准: = 90: 非常安全 = 80: 安全(Secure) = 70: 非常强 = 60: 强(Strong) =

         * 50: 一般(Average) = 25: 弱(Weak) = 0: 非常弱

         */    

        if(grade =90){

            safelevel = Safelevel.VERY_SECURE;

        }else if(grade = 80){

            safelevel = Safelevel.SECURE;

        }else if(grade = 70){

            safelevel = Safelevel.VERY_STRONG;

        }else if(grade = 60){

            safelevel = Safelevel.STRONG;

        }else if(grade = 50){

            safelevel = Safelevel.AVERAGE;

        }else if(grade = 25){

            safelevel = Safelevel.WEAK;

        }else if(grade = 0){

            safelevel = Safelevel.VERY_WEAK;

        }

        return safelevel;

    }

    

    public enum Safelevel {

        VERY_WEAK, /* 非常弱 */

        WEAK, /* 弱 */

        AVERAGE, /* 一般 */

        STRONG, /* 强 */

        VERY_STRONG, /* 非常强 */

        SECURE, /* 安全 */

        VERY_SECURE /* 非常安全 */

    }

}

坐等悬赏。

帮忙说说下面测试密码强中弱程度的JAVA代码中有几个还回是什么意思

相当于权重。其实就是各种字符重要程度的比例。比如说设置个总值是20-弱,30-中,40-强。.

你输入的每个字符对应一个权重值,然后这些值累加。

1,2,4,8这个比例不是固定的,你也可以改的。

呈现这个比例是写的这个人定的。

写一个java正则表达式,判断输入的密码强度,是数字弱,是字母较弱,数字加字母强,用\s写

import java.util.Scanner;

public class JButtonTest

{

public static void main ( String[] args )

{

Scanner scanner = new Scanner (System.in);

System.out.println ("写一个java正则表达式,判断输入的密码强度,是数字弱搜索,是字母较弱,数字加字母强:");

while (scanner.hasNextLine ())

{

String line = scanner.nextLine ();

if (line.matches ("^\\d+$"))

{

System.out.println ("数字弱");

}

else if (line.matches ("^[a-zA-Z]+$"))

{

System.out.println ("字母弱");

}

else if (line.matches ("(?i)^((\\d+[\\da-z]*[a-z]+)|([a-z]+[\\da-z]*\\d+)|([a-z]+[\\da-z]*[a-z]*)|(\\d+[\\da-z]*\\d*))$"))

{

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

}

else

{

System.out.println ("你不按套路出牌啊。你滴承诺尼,你滴担架尼?");

scanner.close ();

break;

}

}

}

}

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判断密码强度和测试密码强度的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

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