Ruby 生成随机密码

2021-11-01 11:45:11 浏览数 (1)

代码语言:javascript复制
def generate_passwd(length=16)
  chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789'
  Array.new(length) { chars[rand(chars.length)].chr }.join
end

#工具脚本,快速生成随机密码

base_char=[]

#定义密码基础字符集

base_char = ('0'..'9').to_a

base_char = ('a'..'z').to_a

base_char = ('A'..'Z').to_a

base_char = ('!'..'/').to_a

base_char.delete("'")

# puts base_cha

#密码长度

size = 16

#生成密码

password = (1..size).map{base_char[rand(base_char.length)]}.join

puts password

0 人点赞