Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, I'm trying to get my login window to only continue a string of code if the user enters 1 of the correct product keys.

The code that I need to execute when 1 of the correct product keys are entered:
MainWindow win2 = new MainWindow();
win2.Show();
this.Close();

If there's a way of showing me how I should set out my data table on my server as well, that would be great.
----------------------------------
Here's the code that currently activates when ANYTHING is in the password box:

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            MainWindow win2 = new MainWindow();
            win2.Show();
            this.Close();
        }

----------------------------------

What I have tried:

I've looked all over Google, but I can't seem to find something that works with password boxes. (I'm quite new to WPF c#)
Posted
Updated 27-Aug-17 22:09pm

 
Share this answer
 
You SQL question is hard to help you with without knowing your SQL server table structure, obviously. Do include for specifics.

A PasswordBox type control supports a property Password server side, however it cannot be bound to for security reasons. See details: [^]

Which me wonder why you're acting on the text changed event of a textbox?
Clearly you don't want to act on every change but not until for instance some button is pressed.

<StackPanel Margin="10">
       <Label>Text:</Label>
       <TextBox />
       <Label>Password:</Label>
       <PasswordBox id="MyPasswordBox" />
   </StackPanel>


and then on the codebehind you can simply access it with

C#
string password = MyPasswordBox.Password;


Of it is boxed in an event like object, remember to unbox it first.

C#
var pwBox = (PasswordBox)sender;


But don't try it if you sender is on your button event ;)
 
Share this answer
 
Comments
Member 13380213 28-Aug-17 8:12am    
Thanks a ton for your help! I have yet decided not use a database and use the application itself instead. I'll accept this as the correct answer as this does work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900