R中的密码生成器功能 [英] Password generator function in R

查看:344
本文介绍了R中的密码生成器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个聪明的方式来编写密码生成器函数在R:

I am looking for a smart way to code a password generator function in R:

generate.password (length, capitals, numbers)




  • length:密码长度

  • 首都:定义资本发生地点的向量,向量反映相应的密码字符串位置,默认值不应为大写

  • 数字:

  • 例如:

    generate.password(8)
    [1] "hqbfpozr"
    
    
    generate.password(length=8, capitals=c(2,4))
    [1] "hYbFpozr"
    
    
    generate.password(length=8, capitals=c(2,4), numbers=c(7:8))
    [1] "hYbFpo49"
    


    推荐答案

    有一种函数可在 stringi (version> = 0.2-3)包中生成随机字符串:

    There is function which generates random strings in the stringi (version >= 0.2-3) package:

    require(stringi)
    stri_rand_strings(n=2, length=8, pattern="[A-Za-z0-9]")
    ## [1] "90i6RdzU" "UAkSVCEa"
    

    您可以为所需的密码生成部件,然后像下面这样粘贴:

    So using different patterns you can generate parts for your desired password and then paste it like this:

    x <- stri_rand_strings(n=4, length=c(2,1,2,3), pattern=c("[a-z]","[A-Z]","[0-9]","[a-z]"))
    x
    ## [1] "ex"  "N"   "81"  "tsy"
    stri_flatten(x)
    ## [1] "exN81tsy"
    

    这篇关于R中的密码生成器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆