Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Existiert Benutzer+Passwort am System? (https://www.delphipraxis.net/6460-existiert-benutzer-passwort-am-system.html)

FriFra 11. Jul 2003 10:20


Existiert Benutzer+Passwort am System?
 
Ich habe 2 strings mit Benutzernamen und Passwort... nun will ich prüfen, ob der bettr. User auch am System existiert und vorallem, ob das angegebene Passwort stimmt.

Gast 11. Jul 2003 10:27

Re: Existiert Benutzer+Passwort am System?
 
Auf NT schaust du mit LogonUser() ob du ein gültiges Token (i.e. Handle) zurückbekommst. Wenn ja, war die User/Password Kombination korrekt.

r_kerber 11. Jul 2003 10:28

Re: Existiert Benutzer+Passwort am System?
 
Falls Du mit System eine Datenbank meinst: Einfach Anmeldung versuchen und anschleißend eventuelle Exception auswerten.

FriFra 11. Jul 2003 11:50

Re: Existiert Benutzer+Passwort am System?
 
Zitat:

Zitat von Assarbad
Auf NT schaust du mit LogonUser() ob du ein gültiges Token (i.e. Handle) zurückbekommst. Wenn ja, war die User/Password Kombination korrekt.

Genau das habe ich gesucht ;). Danke! :dancer: :dancer2:

Motzi 11. Jul 2003 13:47

Re: Existiert Benutzer+Passwort am System?
 
Du wirst allerdings ein Problem haben - unter Win2k muss der Prozess das SE_TCB_NAME Privilege haben, andernfalls scheitert LogonUser und GetLastError liefert ERROR_PRIVILEGE_NOT_HELD! Und das SE_TCB_NAME Privilege ist nur Prozessen der Trusted Computing Base vorbehalten - dem System selbst und den Services

Gast 11. Jul 2003 14:59

Re: Existiert Benutzer+Passwort am System?
 
Zitat:

Remarks
The LOGON32_LOGON_NETWORK logon type is the fastest, but there are two limitations. First, the function returns an impersonation token, not a primary token. You cannot use this token directly in the CreateProcessAsUser function. However, you can call the DuplicateTokenEx function to convert the token to a primary token, and then use it in CreateProcessAsUser. Second, if you convert the token to a primary token and use it in CreateProcessAsUser to start a process, the new process will not be able to access other network resources, such as remote servers or printers, through the redirector. An exception is that if the network resource is not access-controlled, then the new process will be able to access it.

The SE_TCB_NAME privilege is not required for this function unless you are logging onto a Passport account.


Windows 2000: The process calling LogonUser requires the SE_TCB_NAME privilege. If the calling process does not have this privilege, LogonUser fails and GetLastError returns ERROR_PRIVILEGE_NOT_HELD. In some cases, the process that calls LogonUser must also have the SE_CHANGE_NOTIFY_NAME privilege enabled; otherwise, LogonUser fails and GetLastError returns ERROR_ACCESS_DENIED. This privilege is not required for the local system account or accounts that are members of the administrators group. By default, SE_CHANGE_NOTIFY_NAME is enabled for all users, but some administrators may disable it for everyone. For more information about privileges, see Privileges.



The account being logged on, that is, the account specified by lpszUsername, must have the necessary account rights. For example, to log on a user with the LOGON32_LOGON_INTERACTIVE flag, the user (or a group to which the user belongs) must have the SE_INTERACTIVE_LOGON_NAME account right. For a list of the account rights that affect the various logon operations, see Account Rights Constants.

A user is considered logged on if at least one token exists. If you call CreateProcessAsUser and then close the token, the system considers the user as still logged on until the process (and all child processes) have ended.

If the LogonUser call is successful, the system notifies network providers that the logon occurred by calling the provider's NPLogonNotify entry-point function.
Danke Motzi, haette man vielleicht erwaehnen sollen :) BTW: Es geht eh nur bei Services oder wenn der Admin sich selbst die Policy aendert, denn Win32 APIs funzen nicht so einfach von Treibern aus ;)

Nachtrag: Man sollte also einen Service und dann die Anwendung haben. Service schickt Daten an Anwendung und umgekehrt (i.e. IPC).

FriFra 11. Jul 2003 20:30

Re: Existiert Benutzer+Passwort am System?
 
Also ich habe unter XP und 2003 keine Probleme mit dem Befehl... unter NT4 funktioniert es leider nicht... die Sache mit dem Service ist mir eigentlich zu umständlich! Gibt es vielleicht noch einen anderen Weg?

Im Moment verwende ich folgrnden Code:
Delphi-Quellcode:
var
  MyToken: cardinal;
begin
  MyToken := 0;
  try
    LogonUser(PChar(trim(RequestInfo.AuthUsername)), '',
      PChar(trim(RequestInfo.AuthPassword)), LOGON32_LOGON_BATCH,
      LOGON32_PROVIDER_DEFAULT, MyToken);
  except
  end;
  if MyToken <> 0 then
  begin
    //Name und Passwort sind gültig
    ...

sakura 11. Jul 2003 20:34

Re: Existiert Benutzer+Passwort am System?
 
Such bei MSDN mal nach ImpersonateUser, oder so ähnlich. Das ist etwas komplizierter, funktioniert dafür aber auch in normalen Anwendungen.

...:cat:...

Gast 11. Jul 2003 20:57

Re: Existiert Benutzer+Passwort am System?
 
@sakura, das macht nicht viel sinn. du brauchst das token eines eingeloggten users (noch mal der name der API: ImpersonateLoggedonUser ... eine andere API mit aehnlichem namen gibts nicht) . das bekommst du nur mit LogonUser ... oder indem du das token des aktuellen users benutzt.

tokens zusammenbasteln darf eben nur die TCB :)

Ergo: ich kenne keine leichtere moeglichkeit. ich schau nochmal bei Brown rein, aber ich denke es gibt keine bessere variante.

sakura 11. Jul 2003 21:13

Re: Existiert Benutzer+Passwort am System?
 
@Assarbad: :oops: Du hast recht, da habe ich etwas durcheinander gebracht. Anders hatte ich es auch nicht genutzt - war halt schon gut eineinhalb Jahre her, daß ich es gebraucht hatte...

@FriFra: Sorry. :D

...:cat:...


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:07 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz