会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132474个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 15226楼
JAVA 全系列/第六阶段:项目管理与SSM框架/SpringMVC 15227楼

package test;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

public class Shiro_MD5Test {
    public static void main(String[] args) {
        IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:shiro_Md5.ini");
        SecurityManager securityManager = factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken("nd", "123456");
        try {
            subject.login(token);
            if (subject.isAuthenticated()){
                System.out.println("登陆成功");
            }
        }catch (Exception e){
            System.out.println("登录失败");
        }
    }
}
package realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserRealm extends AuthorizingRealm {
    //授权方法
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    //认证方法
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shiro?useUnicode=true&characterEncoding=utf8&useSSL=false","root","123456");
            PreparedStatement preparedStatement = connection.prepareStatement("select userpassword from user where username = ?");
            //获取用户输入的用户名,插入到语句中
            preparedStatement.setString(1, (String) authenticationToken.getPrincipal());
            ResultSet resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                //根据用户输入的用户名去比较密码是否一致
                SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(authenticationToken.getPrincipal(), resultSet.getString("userpassword"), ByteSource.Util.bytes("lf"), "userRealm");
                //如果有值则返回
                return info;
            }
        }catch (Exception e){
            System.out.println("认证方法异常");
        }
        return null;
    }
}
[main]
credentialsMatcher=org.apache.shiro.authc.credential.HashedCredentialsMatcher
#设置加密的类型
credentialsMatcher.hashAlgorithmName=md5
#设置迭代的次数
credentialsMatcher.hashIterations=2

#配置realm
userRealm=realm.UserRealm
userRealm.credentialsMatcher=$credentialsMatcher
securityManager.realms=$userRealm

这个加密是怎么执行的,他们各个语句之间执行顺序是什么,越学越蒙了,麻烦详细说一下

JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 15228楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 15231楼
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 15233楼
人工智能/第九阶段:机器学习-概率图模型(旧)/贝叶斯分类 15234楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/虚拟环境 15235楼
Python 全系列/第五阶段:数据库编程/python操作mysql(旧) 15237楼

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Math</title>
</head>

<body>
    <script>
        /* Math
        1. Math.round 取整 >=0.5 取1 <0.5 取0
        2.Math.floor() 向下取整  返回小于参数值的最大整数
        var num=Math.floor(2.8)  //2
         2.Math.floor() 向上取整  返回大于参数值的最大整数
        var num=Math.floor(2.1)  //3
        3.Math.abs() 绝对值
        4. 3.Math.Max() 最大值
        5.Math.min() 最小值
        6.Math.pow(2,3)  //8 ,2的三次方
        7.Math.sqrt(num)  //返回num的平方根,如果num为负数 返回NaN
        8.Math.random()  返回[0,1)的随机数
        */
        // console.log(Math.round(1.3));
        // var num1=Math.floor( Math.random()*5+10);
        // console.log(num1);

        //大乐透
        var str = '';
        for (var i = 1; i <= 7; i++) {
            var num =0;
            if (i <= 5) {
                 num = Math.floor(Math.random() * 31 + 1);  
                  str+=num+',';
             
                }  else{
                    if(i<7){   num = Math.floor(Math.random() * 15 + 1);  
                    str =num+','+str;
                   }else{
                    num = Math.floor(Math.random() * 15 + 1);  
                    str =str +num;
                   }
                 
                }
               
             
               
        }
        console.log(str);
     


    </script>
</body>

</html>

老师我设计了最后两个数字在1-16 的随机数 为啥还超了16image.png

WEB前端全系列/第二阶段:JavaScript编程模块/Math与Date 15238楼

进度条.zip

为什么我选择了文件不能上传呢

WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 15239楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637