Automatically create User per Powershell

Moderator: Project members

Post Reply
Message
Author
hendrik.schinnenburg
500 Command not understood
Posts: 2
Joined: 2024-02-09 07:38
First name: Hendrik
Last name: Schinnenburg

Automatically create User per Powershell

#1 Post by hendrik.schinnenburg » 2024-05-13 10:52

Hi,
in Powershell i use a script which create Users from a MySQL Database.
The only thing which doesn't work is the Password.

I Do the following:

Code: Select all

$ftp_password = [ Text.Encoding ]::UTF8.GetBytes( $brow .ftp_password.Trim ()) 

$iterations = 100000 

# Erzeugen Sie das Salt 
$salt = New-Object Byte[] 32 
[ Security.Cryptography.RNGCryptoServiceProvider ]::Create().GetBytes( $salt ) 
# Dann können Sie die Funktionen verwenden, um das Salt und den Hash zu generieren 
#Encryption 

# Erzeugen eines Hashes mit PBKDF2 
$rng = New-Object Security.Cryptography.Rfc2898DeriveBytes $ftp_password , $salt , 100000 
$hash = $rng .GetBytes ( 32 ) 

# Zum Schluss können Sie das Salt und den Hash in Base64 konvertieren 
$null = $saltBase64 = [ System.Convert ]::ToBase64String( $salt ) 
$null = $hashBase64 = [ System.Convert ]::ToBase64String( $hash ) 

$null = $hash = $xml .CreateElement ( "hash" ) 
$null = $hash .InnerText = $hashBase64 
$null = $password .AppendChild ( $hash ) 
$null = $salt = $xml .CreateElement ( "salt" ) 
$null = $salt .InnerText = $saltbase64 
$null = $password .AppendChild ( $salt ) 
$null = $iterationsxml = $xml .CreateElement ( "iterations" ) 
$null = $iterationsxml .InnerText = $iterations 
$null = $password .AppendChild ( $iterationsxml ) 

$null = $newUser .AppendChild ( $password ) 
Anyone who does this in the backwards? Or someone who knows what to do?

Thanx a lot

User avatar
botg
Site Admin
Posts: 35634
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse

Re: Automatically create User per Powershell

#2 Post by botg » 2024-05-14 07:50

Which HMAC are you using?

Post Reply