PU identities (users) and passwords

Hi.

I have created a couple of identities within Powershell Universal but the logins are not working.

My authentication.ps1 looks like this:

Set-PSUAuthenticationMethod -Type "Form" -ScriptBlock {

param(
    [PSCredential]$Credential
)

#
#   You can call whatever cmdlets you like to conduct authentication here.
#   Just make sure to return the $Result with the Success property set to $true
#

if ($Credential.UserName -eq 'Admin' -and $Credential.GetNetworkCredential().Password -eq '123') 
{
    New-PSUAuthenticationResult -Success -UserName 'Admin'
}
else 
{
    New-PSUAuthenticationResult -ErrorMessage 'Bad username or password'
}

# elev
if ($Credential.UserName -eq 'elev' -and $Credential.GetNetworkCredential().Password -eq '123') 
{
    New-PSUAuthenticationResult -Success -UserName 'elev'
}
else 
{
    New-PSUAuthenticationResult -ErrorMessage 'Bad username or password'
}

} 

The admin login works but not the user ‘elev’. What am im doing wrong here?

PSU doesnt support Danish, you need to change “elev” to “Student”. (jk)

What happens here is that with username “elev” it fails to evaluate as “admin” and the script ends.

try

if ($Credential.UserName -eq 'Admin' -and $Credential.GetNetworkCredential().Password -eq '123') 
{
    New-PSUAuthenticationResult -Success -UserName 'Admin'
}
elseif ($Credential.UserName -eq 'elev' -and $Credential.GetNetworkCredential().Password -eq '123')
{
    New-PSUAuthenticationResult -Success -UserName 'elev'
}
else 
{
    New-PSUAuthenticationResult -ErrorMessage 'Bad username or password'
}


Thanks alot PorreKaj! It works.

Have a dejlig weekend :slight_smile: