SQL_Server 密码生成函数

说明:生成一个自定义位数的密码,密码可能由以下元素随机组合而成

一:0,1,2,3,4,5,6,7,8,9

二:a到z(小写)

三:A到Z(大写)

四:!,@,#,$,^,&,*,(,),_,+

使用方法:select(print) dbo.getpwd(密码位数)

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
CREATE FUNCTION GetPwd(@count int)
RETURNS varchar(8000)
AS
begin
    
declare @temp table(id int identity primary key,pwd char(1))
    
declare @i int,@sql varchar(1000)
    
set @i=0
    
while @i<10
        
begin
            
insert into @temp select ltrim(@i)
            
set @i=@i+1
        
end
    
set @i=65
    
while @i<91
        
begin 
            
insert into @temp select char(ltrim(@i))
            
set @i=@i+1
        
end
    
set @i=97
    
while @i<123
        
begin 
            
insert into @temp select char(ltrim(@i))
            
set @i=@i+1
        
end
    
insert into @temp select '!'
        
union all select '@'
        
union all select '#'
        
union all select '$'
        
union all select '%'
        
union all select '^'
        
union all select '&'
        
union all select '*'
        
union all select '('
        
union all select '_'
        
union all select '+'
        
union all select '~'
    
declare @s varchar(8000)
    
set @i=0
    
while @i<@count
        
begin
            
select top 1 @s=isnull(@s,'')+pwd from @temp order by (select * from V_getnewid)
            
set @i=@i+1
        
end
    
return @s
end
go
CREATE view V_getnewid
    
AS
select newid() AS rand_id
go 
select dbo.GetPwd(16)

go
--结果:

ExpandedBlockStart.gifContractedBlock.gif
/**//*

Re~IWVYLe3s%#Tqo

*/
  

 

 

转载于:https://www.cnblogs.com/zc_0101/archive/2009/07/13/1522641.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值