Authenticate User: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
Line 8: Line 8:
== Function ==
== Function ==
I have not written a macro for this function.
I have not written a macro for this function.
=== Usage ===
Uso === ===
Use the following code in your NSIS installer to find out if a domain, username, and password authenticate:
Use o seguinte código em seu instalador NSIS para descobrir se um domínio, nome de usuário, senha e autenticação:highlight
<highlight-nsis>
<highlight-nsis>
Push "a_username"
Push a_username "
Push "ADOMAIN"
Push ADOMAIN "
Push "a_password"
Push a_password "
Call MSWAuthenticate
Call MSWAuthenticate
Pop $0 ; = "success" on succes, or "Logon failure: ..." otherwise.
Pop $ 0; = "sucesso" na sucessão, ou "Falha de logon: ..." em contrário.
</highlight-nsis>
</> Destacar-nsis


=== Code ===
=== Code ===

Revision as of 02:27, 11 May 2010

Author: HotButteredSoul (talk, contrib)


NSIS forum thread

Description

This is a function to validate a Windows Username and Password.

Function

I have not written a macro for this function. Uso === === Use o seguinte código em seu instalador NSIS para descobrir se um domínio, nome de usuário, senha e autenticação:highlight

Push a_username "
Push ADOMAIN "
Push a_password "
Call MSWAuthenticate
Pop $ 0; = "sucesso" na sucessão, ou "Falha de logon: ..." em contrário.
</> Destacar-nsis
 
=== Code ===
<highlight-nsis>
#
# MSWAuthenticate.nsh - by HotButteredSoul
#
# Function for checking to see if a Microsoft Windows Username/password
# pair authenticate.
#
 
!ifndef _MSWAuthenticate_nsh
!define _MSWAuthenticate_nsh
 
#
# MSWAuthenticate - authenticates username/password pair
#
# Example:
#
# Push "bob.username"
# Push "ADOMAIN"
# Push "bobs.password"
# Call MSWAuthenticate
# Pop $0 ; = "success" on succes, or "Logon failure: ..." otherwise.
#
# Uses advapi32.lib LogonUserA
#
Function MSWAuthenticate
    Exch $0 ; password (IN)
    Exch
    Exch $1 ; Domain (IN) / "success" (OUT)
    Exch 2
    Exch $2 ; Username (IN)
    Push $3 ; LogonUserA return code
    Push $4 ; GetLastError() code
 
    ; LOGON32_LOGON_NETWORK = 3
    ; LOGON32_PROVIDER_DEFAULT = 0
    System::Call "advapi32::LogonUserA(t r2, t r1, t r0, i 3, i 0, *i) i .r3 ?e"
    Pop $4 ; the ?e flag from System::Call pushes the result of GetLastError() onto the stack.
    IntCmp 0 $3 reject ; return value of 0 is failure.
    StrCpy $1 "success"
    GoTo done
 
    reject:
    IntCmp   87 $4 ERROR_LOGON_FAILURE
    IntCmp 1326 $4 ERROR_LOGON_FAILURE
    IntCmp 1327 $4 ERROR_ACCOUNT_RESTRICTION
    IntCmp 1328 $4 ERROR_INVALID_LOGON_HOURS
    IntCmp 1329 $4 ERROR_INVALID_WORKSTATION
    IntCmp 1330 $4 ERROR_PASSWORD_EXPIRED
    IntCmp 1331 $4 ERROR_ACCOUNT_DISABLED
    ;an error of some other sort
        StrCpy $1 "Logon failure: $4"
        GoTo done
    ERROR_LOGON_FAILURE:
        StrCpy $1 "Logon failure: unknown user name or bad password."
        GoTo done
    ERROR_ACCOUNT_RESTRICTION:
        StrCpy $1 "Logon failure: user account restriction."
        GoTo done
    ERROR_INVALID_LOGON_HOURS:
        StrCpy $1 "Logon failure: account logon time restriction violation."
        GoTo done
    ERROR_INVALID_WORKSTATION:
        StrCpy $1 "Logon failure: user not allowed to log on to this computer."
        GoTo done
    ERROR_PASSWORD_EXPIRED:
        StrCpy $1 "Logon failure: the specified account password has expired."
        GoTo done
    ERROR_ACCOUNT_DISABLED:
        StrCpy $1 "Logon failure: account currently disabled."
        GoTo done
 
    done:
    Pop $4
    Pop $3
    Pop $2
    Pop $0
    Exch $1
FunctionEnd
!endif ; _MSWAuthenticate_nsh


Resources and Links

API Functions used: