Pop-up login dialog box

G

Guest

Hello,

I am programming in Visual Basic .NET. I have seen examples of creating a
login form to use for users to type in their username and password, but I
want to accomplish the same thing with a pop-up dialog box instead. How can
I make my program bring up a pop-up login dialog box for a user to type in
username and password?

Thanks,
Dusty
 
C

Curtis

You can call a login form as a dialog box with the following code:

Dim frmNewDownload As New frmDownload
frmNewDownload.ShowDialog()

That will give your users a dialog box but still allow you to design the
form to your specs.

Curtis
 
H

Herfried K. Wagner [MVP]

Dusty Hackney said:
I am programming in Visual Basic .NET. I have seen examples of creating a
login form to use for users to type in their username and password, but I
want to accomplish the same thing with a pop-up dialog box instead. How
can
I make my program bring up a pop-up login dialog box for a user to type in
username and password?

If you are using VS 2005:

Select "Project" -> "Add new item..." -> "Login Form" -> "Add". Then use
the following code to display the login dialog:

\\\
Using f As New LoginForm()
If f.ShowDialog = DialogResult.OK Then
Password = f.PasswordTextBox.Text
Username = f.UsernameTextBox.Text
End If
End Using
///
 
C

Cor Ligthert [MVP]

Herfried,
\\\
Using f As New LoginForm()
If f.ShowDialog = DialogResult.OK Then
Password = f.PasswordTextBox.Text
Username = f.UsernameTextBox.Text
End If
End Using
///
It sound strange, however normally it will not needed ot return the
password, that can be checked in the dialog itself. An Ok is more than
enough and than in the code.

If f.showdialog <> dialogresult.OK me.close

A typical question for you. How do I get rit of that error warning (shared
member) with this in VB2005?

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
It sound strange, however normally it will not needed ot return the
password, that can be checked in the dialog itself. An Ok is more than
enough and than in the code.

If f.showdialog <> dialogresult.OK me.close

Mhm... So you think it's a good idea to return 'DialogResult.OK' to
represent valid login data? I do not like this idea. The value of
'DialogResult' should IMO be set by the button selected on the form.
A typical question for you. How do I get rit of that error warning (shared
member) with this in VB2005?

Where's that error warning?
 
C

Cor Ligthert [MVP]

Cor,
Mhm... So you think it's a good idea to return 'DialogResult.OK' to
represent valid login data? I do not like this idea. The value of
'DialogResult' should IMO be set by the button selected on the form.
You don't need that password in your application, so why would you than get
it in that, you only need to verify that the user is a right one. (It can be
that you with this system have to transport back his/hers rights however
that is something else).
Where's that error warning?

Sorry not an error warning, one of those that you like so much a 'warning'.
(which means not like so much)
(Access to a shared member etc)

Windows.Forms.DialogResult.OK
'gives no warning
DialogResult.OK

'gives warning

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
You don't need that password in your application, so why would you than
get it in that, you only need to verify that the user is a right one. (It
can be that you with this system have to transport back his/hers rights
however that is something else).

This depends on the case. Maybe you need the password when establishing a
connection to a database. I would not place the database-related code
inside the login dialog.
Sorry not an error warning, one of those that you like so much a
'warning'. (which means not like so much)
(Access to a shared member etc)

Windows.Forms.DialogResult.OK
'gives no warning
DialogResult.OK

'gives warning

That's interesting. I currently only have the August CTP at hand, but the
code compiles just fine without a warning inside a form, althout the warning
is enabled. However, according to the IDE 'DialogResult' is resolved to the
form's property instead of the enumeration.
 
C

Cor Ligthert [MVP]

Herfried,
This depends on the case. Maybe you need the password when establishing a
connection to a database. I would not place the database-related code
inside the login dialog.

You get it forever from the database otherwise you can use the
IsInRoleMethod. In my opinion is the logic about the checking the best
placed in that login class (in a seperated DLL) and not spread over a kind
of main class. While you use in that login class of course the logic from
your database layer class(es).

Just my thought,

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
You get it forever from the database otherwise you can use the
IsInRoleMethod. In my opinion is the logic about the checking the best
placed in that login class (in a seperated DLL) and not spread over a kind
of main class. While you use in that login class of course the logic from
your database layer class(es).

Yep, but the login dialog is part of the presentation layer and doesn't
belong to the data layer. And, finally you have to pass login data to the
data layer to establish the connection, for example.
 
G

Guest

This seems to only work in a Windows Form. However, what I am working with
is a Web Form. Is there a way to make it work for the web form, or is there
another way in the web forms that I can accomplish this?

Thanks,
Dusty
 
G

Guest

Thanks for the input. I think that I will be able to use this for a
different project I am working on. However, I would still like to know how
to make the pop-up login box work for my current project because my boss
would like to be able to bring up a login box on-demand (perhaps even from a
button). One of the reasons he would like the pop-up box is in the instance
if one of our HR people leaves there computer unattended then someone can't
sit down and run the programs we wrote for them without knowing that HR
person's password.
 
C

Cor Ligthert [MVP]

The using does in VB2005 the same as the changes I made bellow

\\\
dim f As New LoginForm()f.dispose
///

That is all

I hope this helps,

Cor
 
C

Cor Ligthert [MVP]

Dusty,

Have a look at the complete message thread, Herfried and I had a pleasant
discussion about your problem and although we go sometimes in this newsgroup
to a sideline (and than it is a complete other problem), was this was almost
only about your problem.

Cor
 
G

Guest

Cor,

Thanks. The problem is that I am working with web forms so the ShowDialog
method isn't available. How can I accomplish this pop-up dialog when working
with web forms?

Thanks,
Dusty
 
H

Herfried K. Wagner [MVP]

Dusty Hackney said:
Thanks. The problem is that I am working with web forms so the ShowDialog
method isn't available. How can I accomplish this pop-up dialog when
working
with web forms?

I suggest not to use Web Page dialogs. Instead, use a login page.
 
C

Cor Ligthert [MVP]

Dusty,

If you had sad that before than it would have been easier to answer you.
This newsgroup has default a windowsform, while we do as well aspnet
normally with code behind.

However, around the login with a webpage are more aspects than only the
code, which can in my opinion better be handled in the framework newsgroup
for ASPNET or a security newsgroup.

In my opinion it is better that you start asking this in this newsgroup.

microsoft.public.dotnet.framework.aspnet

I assume that if needed they tell you what security newsgroup is than the
best for your problem.

I think that you have with this much more as answer than that we start
helping you here with that,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top