Board logo

标题: [转载代码] [PowerShell每日技巧]创建随机密码(20131211) [打印本页]

作者: DAIC    时间: 2013-12-23 11:26     标题: [PowerShell每日技巧]创建随机密码(20131211)

Here's a chunk of code that creates random passwords of different lengths for you:
  1. $length = 8
  2. $characters = [Char[]]((31..50) + (65..90) + (97..122))
  3. $characters = $characters -ne 'O' -ne 'o' -ne 'l' -ne '1' -ne '-'
  4. $password = -join ($characters | Get-Random -Count $length)
  5. "Your temporary $length-character-password is $password"
复制代码
The password length is set by $length. The characters used to compose the passwords are defined in $characters. By default, all ASCII codes from 31-50, 65-90, and 97-122 are used. As you can see, with the -ne operator, you can fine-tune the list and exclude characters. In our example, we exclude characters that can easily be misinterpreted.

http://powershell.com/cs/blogs/tips/archive/2013/12/11/creating-temporary-password.aspx
作者: terse    时间: 2014-1-29 17:07

也发现一个
  1. Add-Type -AssemblyName System.Web
  2. [System.Web.Security.Membership]::GeneratePassword(10,2)
复制代码

作者: PowerShell    时间: 2014-4-17 22:52

it人的终极梦想是什么?
答:先进的技术,就像下述电影里演的那样。
“电脑:启动医学紧急全息投影程序!” ----------太好了!
推荐观看 星际旅行---航海家号 1-7季全集,清晰度=h.264,字幕=外挂
http://pan.baidu.com/s/1sjrVI1J

“电脑,护盾全开,导弹全轰!”

“呀被打败了,启动自毁程序,安全码是xxx”

“呀,安全码几百年没改,被人穷举出来改掉了,不灵了。。。”

观众:“靠~~~~”

身为it人,密码还总不灵,真是%#¥%#¥%……

特奉献我写的密码生成脚本:
1 密码生成位数,默认为8,容易修改
2 默认8位,大小写+数字,修改脚本第19行。
3 默认每次产生1000个密码,在d:\tools\小写加数字密码.txt    含大写密码.txt    含特殊符号密码.txt
4每生成一个字母后,都随机延时,生成的比较慢,要n个小时,但随机性可靠,开了程序,一晚上就会产生很多密码在文本中,用时随意取,并在文本中标注即可。
5 傻瓜都能懂,菜鸟都能改。
作者: PowerShell    时间: 2014-4-17 22:53

  1. <#
  2. 转帖
  3. 管理员不能无耻到如此程度!!!---------------人家好心好意把你网站的漏洞报给你,你却把人加入了黑名单!
  4. CSDN 600万 人人500万  多玩800万 等等 互联网泄密风云仍在继续!!就在刚刚 本站又获得消息 国内著名的域名注册商xinnet 新网的 管理员密码造泄漏!
  5. 此消息由国内著名安全漏洞网站WooYun 爆出!
  6. 保守估计漏洞爆出的 域名管理密码在30万以上。这个漏洞最早在2010年2月就被发现,当时就已经与新网取得联系但是石沉大海 没有任何回复,当近期再次联系时发现邮箱地址已经被对方列入黑名单!
  7. 长达两年时间 这个漏洞一直没有修复。完全是不把用户安全放在心上!用户安全荡然无存。
  8. 为此,本人特贡献,生成8位随机密码的powershell脚本!
  9. #>
  10. $每个密码位数 = 8
  11. $存盘目录 = 'd:\TOOLS\'
  12. $纯小写密码 = $存盘目录 + '纯小写密码.txt'
  13. $小写加数字密码 = $存盘目录 + '小写加数字密码.txt'
  14. $含大写密码 = $存盘目录 + '含大写密码.txt'
  15. $含特殊符号密码 = $存盘目录 + '含特殊符号密码.txt'
  16. $密码类型 = 3   # 4=小写+数字+特殊符号,3=大写+小写+数字,2=小写+数字
  17. $生成密码总个数 = 1000
  18. mkdir   $存盘目录
  19. Write-Host "---每生成一个字母后,都随机延时---"
  20. Write-Host "---生成的比较慢,但随机性可靠---"
  21. $随机延时 =  50,60,70,100,200,88,95,111,120,135,146,160,170,181,189
  22. for ($l=$生成密码总个数;$l -gt 0;$l--)
  23. {
  24. [string]$结果 = "a","b","c","d","e","f","g","h","i","j","k","m","n","p","q","r","s","t","u","v","w","x","y","z" | Get-Random
  25.     Start-Sleep -m ($随机延时  | Get-Random)
  26.     #某些网站有别扭的要求“密码首字符必须为字母”,所以本程序首字符,固定为小写字母,
  27. for ($i=1;$i -lt $每个密码位数;$i++)
  28. {
  29. $小写字母 = "a","b","c","d","e","f","g","h","i","j","k","m","n","o","p","q","r","s","t","u","v","w","x","y","z" | Get-Random
  30. #小写字母没有字母 l
  31. Start-Sleep -m ($随机延时  | Get-Random)
  32.    
  33. $数字 = "2","3","4","5","6","7","8","9"  | Get-Random
  34. #没有0,1
  35.     Start-Sleep -m ($随机延时  | Get-Random)
  36. $大写字母 = "A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z" | Get-Random
  37. #大写字母没有字母 I,O
  38. Start-Sleep -m ($随机延时  | Get-Random)
  39.     $特殊符号 = "~","!","@","#","$","%","^","&","*","(",")" | Get-Random
  40. #大写字母没有字母 I,O
  41. Start-Sleep -m ($随机延时  | Get-Random)
  42. switch ($密码类型)
  43. {
  44. #1   {$结果 = $结果 + $小写字母;break}
  45. 2  {$结果 = $结果 + ($小写字母,$数字| Get-Random) ; break}
  46. 3  {$结果 = $结果 + ($小写字母,$数字,$大写字母| Get-Random) ; break}
  47. 4  {$结果 = $结果 + ($小写字母,$数字,$特殊符号| Get-Random) ; break}
  48. }
  49. }
  50. #洗牌
  51. $结果 = $结果 | Get-Random  -Count   $每个密码位数
  52. if ( $结果 -match "[~!@#$%^&*()]+"  )
  53. {
  54. $结果 >> $含特殊符号密码
  55. }
  56. if (  ($结果 -notmatch "[~!@#$%^&*()]+")   -and   ($结果 -cmatch "[A-Z]+")  )
  57. {
  58. $结果 >> $含大写密码
  59. }
  60. if (  ($结果 -notmatch "[~!@#$%^&*()]+")   -and   ($结果 -cnotmatch "[A-Z]+")   )
  61. {
  62. $结果 >> $小写加数字密码
  63. }
  64. Write-Host "."   -NoNewline  -ForegroundColor Yellow
  65. }
  66. Write-Host "`n---完成 $生成密码总个数 个密码创建---"  
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2