Created
August 24, 2012 08:45
-
-
Save dotted/3447657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $Global:passwordPath = $("$env:APPDATA\dotuserpass.xml") | |
| $Global:passwordXml = @{} | |
| $Global:loggedin = $false | |
| <# | |
| Unserialize xml into object | |
| #> | |
| function load_passwords() | |
| { | |
| try | |
| { | |
| $Global:passwordXml = Import-Clixml -path $Global:passwordPath | |
| Write-Host "User database loaded" | |
| return $true | |
| } | |
| catch | |
| { | |
| Write-Host "User database could not be loaded" | |
| return $false | |
| } | |
| } | |
| <# | |
| Serialize object and store in xml | |
| #> | |
| function save_passwords() | |
| { | |
| try | |
| { | |
| Export-Clixml -InputObject $Global:passwordXml -Path $Global:passwordPath -Force | |
| Write-Host "User database saved" | |
| return $true | |
| } | |
| catch | |
| { | |
| Write-Host "User database could not be saved" | |
| return $false | |
| } | |
| } | |
| <# | |
| @param $username: String with desired username | |
| @param $password: Strin with desired password | |
| #> | |
| function create_user([string]$username, [string]$password) | |
| { | |
| $Global:passwordXml["$username"] = "$password" | |
| save_passwords | |
| } | |
| <# | |
| @param $username: String with username | |
| @param $password: Strin with password | |
| #> | |
| function login([string]$username, [string]$password) | |
| { | |
| if ($Global:passwordXml["$username"] -eq $password) | |
| { | |
| $Global:loggedin = $true | |
| Write-Host "Login successful" | |
| return $true | |
| } | |
| else | |
| { | |
| Write-Host "Login failed" | |
| return $false | |
| } | |
| } | |
| function logout() | |
| { | |
| try | |
| { | |
| $Global:loggedin = $false | |
| Write-Host "Logout successful" | |
| return $true | |
| } | |
| catch | |
| { | |
| Write-Host "Logout failed" | |
| return $false | |
| } | |
| } | |
| load_passwords > nul | |
| Write-Host "Ready." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment