Java开源 | PHP开源 | .NET开源 | Android | Linux操作系统 | Ajax | jQuery插件 | Web服务器 | 开发工具 | Web Service | 可视化HTML编辑器 | 常用JS库 | 开源手机软件
讨论区首页 » 开源软件交流 » MySQL » 用MySQL生成随机密码
转帖:

用MySQL生成随机密码

作 者话 题 正 文

晚上有朋友问起,简单的写了一个。
DELIMITER $$

CREATE
    FUNCTION `t_girl`.`func_rand_string`(f_num tinyint unsigned,f_type tinyint unsigned)
    RETURNS varchar(32)
    BEGIN
      -- Translate the number to letter.
      -- No 1 stands for string only.
      -- No 2 stands for number only.
      -- No 3 stands for combination of the above.
      declare i int unsigned default 0;
      declare v_result varchar(255) default '';
      while i < f_num do
        if f_type = 1 then
          set v_result = concat(v_result,char(97+ceil(rand()*25)));
        elseif f_type=2 then
          set v_result = concat(v_result,char(48+ceil(rand()*9)));
        elseif f_type=3 then
          set v_result = concat(v_result,substring(replace(uuid(),'-',''),i+1,1));
        end if;
        set i = i + 1;
      end while;
      return v_result;

    END$$

DELIMITER ;


调 用方法示例:
select func_rand_string(12,3);

返回顶部 回复此话题 | 关注此话题
如果您尚未登录,点击此按钮将会提示登录界面