Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- [Parameter(Mandatory=$true)][string]$user,
- [Parameter(Mandatory=$false)][string]$email
- )
- function generate_password{
- #foreach ($line in $word) {if ($line.length -gt 8) {$line | out-file sorting.txt -append}}
- #foreach ($line in $word) {(Get-Culture).TextInfo.ToTitleCase($line) | out-file ordlista.txt -append}
- #get-content ordlista.txt | foreach { $_ + '123!' } | set-content ordlista.txt
- $wordlist = Get-Content .\ordlista.txt
- $password = Get-Random -InputObject $wordlist
- return $password
- }
- Function Test-UserCredential {
- #creds > https://serverfault.com/questions/67706/tool-to-test-a-user-account-and-password-test-login
- Param($username, $password)
- Add-Type -AssemblyName System.DirectoryServices.AccountManagement
- $ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine, $env:computername
- $opt = [System.DirectoryServices.AccountManagement.ContextOptions]::SimpleBind
- $pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ct
- $Result = $pc.ValidateCredentials($username, $password).ToString()
- return $Result
- }
- function test_email($pass){
- $From = "awefawefabre@gmail.com"
- $To = $email
- $Cc = ""
- $Subject = "Password reset"
- $Body = "Your new password is: $pass "
- $SMTPServer = "smtp.gmail.com"
- $SMTPPort = "587"
- Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential)
- }
- function google_email($pass){
- $EmailTo = $email
- $EmailFrom = "awefawefabre@gmail.com"
- $Subject = "password reset"
- $Body = "Your new password is:$password"
- $SMTPServer = "smtp.gmail.com"
- $SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
- $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
- $SMTPClient.EnableSsl = $true
- $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("awefawefabre@gmail.com", "Tesla123")
- $SMTPClient.Send($SMTPMessage)
- }
- function main{
- $password = generate_password
- $securestring = ConvertTo-SecureString $password –asplaintext –force
- try{
- Set-ADAccountPassword $user -NewPassword $securestring -Reset -PassThru | Set-ADuser -PasswordNeverExpires $false | Set-ADuser -ChangePasswordAtLogon $True
- write-host '[*]Password changed....'
- }
- catch{
- write-host '[-]Cant find that user'
- return
- }
- $domain = ((gwmi Win32_ComputerSystem).Domain).Split(".")[0]
- write-host '[*]Validating new password...'
- $test = Test-UserCredential -username $domain\$user -password $password
- if($test){
- write-host "[+]Successful, new password is:$password"
- }
- else{
- write-host '[-]Error, password not changed'
- return
- }
- if ($email){
- write-host '[*]Sending email..'
- try {
- google_email($password)
- write-host '[+]Email sent!'
- }
- catch{
- write-host '[-]Error sending mail'
- }
- }
- }
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement