Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ErrorActionPreference = "STOP"
- $sqlServer = "127.0.0.1"
- $sqlUser = "cohserver"
- $sqlPassword = "freecoh"
- $sqlDb = "cohauth"
- $userName = "coh"
- $userId = 200
- $userPassword = "coh"
- function Get-Adler32 {
- param(
- [string] $data
- )
- $mod_adler = 65521
- $a = 1
- $b = 0
- $len = $data.Length
- for ($index = 0; $index -lt $len; $index++) {
- $a = ($a + [byte]$data[$index]) % $mod_adler
- $b = ($b + $a) % $mod_adler
- }
- return ($b -shl 16) -bor $a;
- }
- function Get-HashedPassword {
- param(
- [string] $UserName,
- [string] $Password
- )
- $a32 = adler32($UserName.ToLower())
- $a32hex = $a32.ToString("x8")
- $a32hex = $a32hex.Substring(6, 2) + $a32hex.Substring(4, 2) + $a32hex.Substring(2, 2) + $a32hex.Substring(0, 2)
- $bytes = [System.Text.Encoding]::UTF8.GetBytes($Password + $a32hex)
- $digest = [System.Security.Cryptography.HashAlgorithm]::Create("SHA512").ComputeHash($bytes)
- return $digest
- }
- function Get-Connection {
- $connection = [System.Data.SqlClient.SqlConnection]::new()
- $connection.ConnectionString = "Server='$sqlServer';Database='$sqlDb';User Id='$sqlUser';Password='$sqlPassword';"
- $connection.Open()
- return $connection
- }
- function Set-UserAccount {
- param(
- [System.Data.SqlClient.SqlConnection] $Connection,
- [string] $UserName,
- [int] $UserId,
- [int] $ForumId
- )
- $command = [System.Data.SqlClient.SqlCommand]::new()
- $command.Connection = $Connection
- $command.CommandText = "INSERT INTO user_account (account, uid, forum_id, pay_stat) VALUES (@UserName, @UserId, @ForumId, 1014);"
- $command.Parameters.AddWithValue("@UserName", $UserName) > $null
- $command.Parameters.AddWithValue("@UserId", $UserId) > $null
- $command.Parameters.AddWithValue("@ForumId", $ForumId) > $null
- $command.ExecuteScalar()
- $command.Dispose()
- }
- function Set-UserAuth {
- param(
- [System.Data.SqlClient.SqlConnection] $Connection,
- [string] $UserName,
- [byte[]] $HashedPassword
- )
- $p = ""
- foreach($byte in $hashedPassword) {
- $p = $p + $byte.ToString("x2");
- }
- $command = [System.Data.SqlClient.SqlCommand]::new()
- $command.Connection = $Connection
- $command.CommandText = "INSERT INTO user_auth (account, password, salt, hash_type) VALUES (@UserName, CONVERT(BINARY(128), '$p'), 0, 1);"
- $command.Parameters.AddWithValue("@UserName", $UserName) > $null
- # Using AddWithValue for the password results in extra bytes being added to the string for some reason?
- # In a rush, so hack it for now
- #$command.Parameters.AddWithValue("@Password", $HashedPassword)
- #$command.Parameters.AddWithValue("@Password", $p)
- $command.ExecuteScalar()
- $command.Dispose()
- }
- function Set-UserData {
- param(
- [System.Data.SqlClient.SqlConnection] $Connection,
- [string] $UserId
- )
- $command = [System.Data.SqlClient.SqlCommand]::new()
- $command.Connection = $Connection
- $command.CommandText = "INSERT INTO user_data (uid, user_data) VALUES (@UserId, 0x0080C2E000D00B0C000000000CB40058);"
- $command.Parameters.AddWithValue("@UserId", $UserId) > $null
- $command.ExecuteScalar()
- $command.Dispose()
- }
- function Set-User {
- param(
- [string] $UserName,
- [string] $Password,
- [int] $UserId,
- [int] $ForumId
- )
- $hashedPassword = Get-HashedPassword -UserName $UserName -Password $Password
- $connection = Get-Connection
- Set-UserAccount -Connection $connection -UserName $UserName -UserId $UserId -ForumId $UserId
- Set-UserAuth -Connection $connection -UserName $UserName -HashedPassword $hashedPassword
- Set-UserData -Connection $connection -UserId $UserId
- $connection.Dispose()
- }
- Set-User -UserName $userName -Password $userPassword -UserId $userId -ForumId $forumId
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement