password form to perform operation from main form

M

ma.giorgi

Hi Everybody!

I have the following problem:
from the application mainForm the user can do several operation
Some of them are password protected
(the password is a code that change everytime on the basis of a
reference code)

so when the user click on a menu in the main form, the passwordForm is
displayed
the user enter the password and click the OK button

now I have a function in the passwordForm that verify the inserted
password against the reference code
if it's correct I can continue to execute the code in the mainForm
else I stop, to perform this my form should return the result to
mainForm and then close...

I can't figure out how to proceed on this, I mean the logic, I don't
want to use the inputbox from vb.dll, only pure C#.

thanks in advance!

marco
 
M

Morten Wennevik [C# MVP]

Hi Marco,

If you display your password form using ShowDialog() you can check either
properties on the form directly, or have passwordForm set a DialogResult
before it closes.

//passwordForm
override OnClosing(... ,...)
{
if(ValidateUser)
this.DialogResult = DialogResult.Yes;
else
this.DialogResult = DialogResult.No;
}

//mainForm

if(passwordForm.ShowDialog() == DialogResult.Yes)
{
//User is valid, execute code
}
 
G

GioX®

Many thanks! it works perfectly

Hi Marco,

If you display your password form using ShowDialog() you can check either
properties on the form directly, or have passwordForm set a DialogResult
before it closes.

//passwordForm
override OnClosing(... ,...)
{
     if(ValidateUser)
        this.DialogResult = DialogResult.Yes;
     else
        this.DialogResult = DialogResult.No;

}

//mainForm

if(passwordForm.ShowDialog() == DialogResult.Yes)
{
     //User is valid, execute code

}

--
Happy Coding!
Morten Wennevik [C# MVP]



Hi Everybody!
I have the following problem:
from the application mainForm the user can do several operation
Some of them are password protected
(the password is a code that change everytime on the basis of a
reference code)
so when the user click on a menu in the main form, the passwordForm is
displayed
the user enter the password and click the OK button
now I have a function in the passwordForm that verify the inserted
password against the reference code
if it's correct I can continue to execute the code in the mainForm
else I stop, to perform this my form should return the result to
mainForm and then close...
I can't figure out how to proceed on this, I mean the logic, I don't
want to use the inputbox from vb.dll, only pure C#.
thanks in advance!
marco- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -
 

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