If the validation has to be with the "authentication of the desktop application using the active login of the web application" (according to your words) the most correct is when the user authenticates in the web application that login generate an authentication "token" in the system.
I advise having a table, for example, "User token" instead of saving in "Session":
CREATE TABLE [dbo].[UsuarioToken] (
[Token] UNIQUEIDENTIFIER NOT NULL,
[IdUsuario] SMALLINT NOT NULL,
[DataInicial] DATETIME DEFAULT (getdate()) NOT NULL,
[DataFinal] DATETIME NULL,
PRIMARY KEY CLUSTERED ([Token] ASC),
CONSTRAINT [FK_UsuarioToken_Usuario] FOREIGN KEY ([IdUsuario]) REFERENCES [dbo].[Usuario] ([idUsuario]));
When you "log in" to the web, you create the token with the access date (Initial Date). When you "drop" the token (Final Date) is inactive. Note that the Initial Date has as value DEFAULT
the getdate()
, to DataFinal
no, because it will be the date and time that the user "dislodges" from the web application. It will be the DataFinal
when NULL
which will indicate whether the token is active or not.
With the token created, it will now depend on your business rule and whatever else is applicable and/or feasible to your situation, so what comes below is just example/idea:
In the desktop application:
Instead of having a form with User and Password, it would have a form to indicate the "access key", token created in the web login, which could be sent to the "client" via e-mail (e-mail this of the user registration data). If active token, ex.: ValidarToken(Guid token)
, does the processing if it does not return which token is invalid.
Yes have a login form with user and password to identify and validate, the first time, if the user (idUsuario) is registered in the web system, after that checks if token ("access key") is associated to the user who is logged in and if token is active in the web system. In short, you identify once if the user and password is valid, if valid checks if there is an active "access key" in the web application, if there stores the token in a variable on the desktop and in the next processes that require token, as it is already stored in memory, only checks whether it is still active in the web application ValidarToken(Guid token)
. If not, go back to the login process again.
I emphasize the security rules, because the token must be invalidated after performing all the necessary processes on the desktop.
You will need to use a webservice for this. Are you aware of this? Without more details the question can be considered as too broad, anyway it is an interesting question +1. By the way, comment when you edit the question and mention me, maybe I can help you.
– Jéf Bueno
You want to use the same data as an already logged-in user, in this case the data from Session, or you want to use the same login and password?
– Randrade
@jbueno Yes, I already know about webservices, but I use Visual Studio and doing a Webmethod in my web application controller, I was not successful. Actually I could not think of the logic of how the data will be provided to the C# desktop application knowing that probably I will have more than one user logged into the system at the same time....
– Jefferson Pedro
@Randrade I want to use the same user data already logged in to prevent the user from having to log in to the desktop application as well. Basically it’s the same application, but there are things that I won’t be able to do on the web and with desktop it’s easier, such as accessing the Windows Certificate Store to use digital certificates for transactions with tax notes in the SEFAZ webservices. I have tried several things, but with the end of the applet near the limits of the web to access the resources of the user’s machine, a valid option is a dual application (web and desktop).
– Jefferson Pedro
@Jeffersonpedro, my answer gives you the path of stones to your problem. If it is not enough to solve it, please give me more information about your application and I will edit my answer to better address your problem.
– Luã Govinda Mendes Souza