Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using Visual Studio 2017 C# .NET Framework 4

I have two forms

My first form has the code below that works. Enter password and click OK

//manually define password because we are not using any database

            string Password = "password";

            if (Password == textBox1.Text)


MessageBox.Show("You have entered an incorrect password, Please re-enter your password again!");

OK    Cancel

My second form has this
Does anyone have the code to make this work so the user can change their password?

Enter your current password

Enter your new password

Enter your new password again

OK    Cancel

What I have tried:

I was able to create my first form and code for Enter password and click OK but I can not figure out how to create code so the user can change their password.
Updated 31-Aug-18 8:08am

1 solution

You can't change the password because you are using a single, fixed password:
string Password = "password";
And you can't change that because it is part of your application.

In order to start writing a "change password" form, you first need to start storing users and their passwords somewhere outside your app - a text or binary file, XML, JSON, whatever - or in a database. Until you have decided exactly how you are going to do that, you can't even start to write a "change password" form because you have no idea where or how it is going to be stored!

And do yourself a favour: Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] but it may be a little too advanced for you at the moment.
Share this answer

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