Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reset an AD user's password using auto password generator

Posted on 2009-04-06
2
Medium Priority
?
1,826 Views
Last Modified: 2013-12-24
Hi,
i have the attached code provided here by Rob to auto generate a password using predetermined rules.
i need a way that would prompt me to enter a username and will reset the user's password to the auto generated value of the script (with the "user must change password at next logon" checked by default)

' Basis from here:
'http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions08/avbsol05.mspx
' Question link:
'http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24276924.html
 
'Description: Auto generates password according to the following rules:
 
' Be at least 8 positions in length but up to 9.
' Contain at least one English letter and one digit character
' Should not contain a digit character in the first and last position!(0-9)
' No special characters - lower case letters and digits only
' Must begin and end with a letter
' Should not contain identical consecutive characters (aa, ##, 88.)
' Should not contain specific words (e.g. help, desk)
 
 
Const MinLength = 8
Const MaxLength = 9
 
While ValidatePassword(strPassword) = False
        strPassword = GeneratePassword
Wend
MsgBox strPassword
 
Function GeneratePassword()
 
        strRndPwd = ""
        
        If MinLength = "" Or MaxLength = "" Then
                WScript.Echo "Min and max lengths are not defined. Please set MinLength and MaxLength globally."
                Exit Function
        End If
        
        Randomize
        intLength = Int((MaxLength - MinLength + 1) * Rnd + MinLength)
 
        Const AsciiLower = 32
        Const AsciiUpper = 126
 
        While Len(strRndPwd) <= intLength
        'Randomize
                strChr = Chr(Int((AsciiUpper - AsciiLower + 1) * Rnd + AsciiLower))
                If (Asc(strChr) >= 48 And Asc(strChr) <= 57) Or (Asc(strChr) >= 97 And Asc(strChr) <= 122) Then strRndPwd = strRndPwd & strChr
        Wend
 
        GeneratePassword = strRndPwd
End Function
 
Function ValidatePassword(strValPwd)
	Set objRegEx = CreateObject("VBScript.RegExp")
	boolValid = True
	' Check the length requirement
	If Len(strValPwd) < MinLength Or Len(strValPwd) > MaxLength Then boolValid = False
	' Look for an english character
	If boolValid = True Then
		objRegEx.Pattern = "[a-z]"
		Set colMatches = objRegEx.Execute(strValPwd)  
		If colMatches.Count = 0 Then boolValid = False
	End If
	' Look for a digit
	If boolValid = True Then
		objRegEx.Pattern = "[0-9]"
		Set colMatches = objRegEx.Execute(strValPwd)  
		If colMatches.Count = 0 Then boolValid = False
	End If
	' Look for a digit in the first or last position
	If boolValid = True Then
		strFirstChr = Left(strValPwd, 1)
		strLastChr = Right(strValPwd, 1)
		If IsNumeric(strFirstChr) Or IsNumeric(strLastChr) Then boolValid = False
	End If
	' Prevent specific words from being the password
	Set objDict = CreateObject("Scripting.Dictionary")
	objDict.Add "ncx", 0
	objDict.Add "kbs", 0
	objDict.Add "qazwsx", 0
	objDict.Add "cns", 0
	objDict.Add "comverse", 0
	objDict.Add "help", 0
	objDict.Add "desk", 0
	If objDict.Exists(strValPwd) = True Then boolValid = False
	' Return the valid code
	ValidatePassword = boolValid
End Function

Open in new window

0
Comment
Question by:johnnyjonathan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 12

Accepted Solution

by:
chandru_sol earned 2000 total points
ID: 24079549
Hi,

HTA in the link below will give you exactly what you needed

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24279527.html

regards
Chandru
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 24127844
Thanks for the Grade!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question