欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Powershell生成Windows密码算法简单学习

程序员文章站 2022-04-09 14:47:13
说明: 1、密码一共8位。 2、由2个数字,2个大写字符,2个小写字符,2个特殊字符组成。 3、字符的次序是随机组成的。 复制代码 代码如下: function creat...
说明
1、密码一共8位。
2、由2个数字,2个大写字符,2个小写字符,2个特殊字符组成。
3、字符的次序是随机组成的。
复制代码 代码如下:

function createpassword
{
$figure=1,2,3,4,5,6,7,8,9;
$capital="q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m";
$lowercase="q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m";
$specialcharacter="~","!","@","#","$","%","^","&","*","(",")","-","+";
$order=new-object system.collections.arraylist;
for($i=0;$i -lt 8;$i++)
{
[void]$order.add($i);
}
$neworder=@();
for($i=0;$i -lt 8;$i++)
{
$produceorder=get-random -inputobject $order;
$neworder+=$produceorder;
$order.remove($produceorder);
}
$newpassword=@();
foreach($i in $neworder)
{
if($i -eq 0)
{
$index=get-random -maximum 8;
$newpassword+=$figure[$index];
}
if($i -eq 1)
{
$index=get-random -maximum 8;
$newpassword+=$figure[$index];
}
if($i -eq 2)
{
$index=get-random -maximum 25;
$newpassword+=$capital[$index];
}
if($i -eq 3)
{
$index=get-random -maximum 25;
$newpassword+=$capital[$index];
}
if($i -eq 4)
{
$index=get-random -maximum 25;
$newpassword+=$lowercase[$index];
}
if($i -eq 5)
{
$index=get-random -maximum 25;
$newpassword+=$lowercase[$index];
}
if($i -eq 6)
{
$index=get-random -maximum 12;
$newpassword+=$specialcharacter[$index];
}
if($i -eq 7)
{
$index=get-random -maximum 12;
$newpassword+=$specialcharacter[$index];
}
}
return $newpassword -join "";
}

测试结果
Powershell生成Windows密码算法简单学习