I am making a password manager. At the start of the program it prompts for a password. I want to give the user the option to specify this password to what ever he/she wants. Would i save it in an XML file. If so how.

Recommended Answers

All 7 Replies

You can store it in the registry:

// Save data
RegistryKey regKey = Registry.CurrentUser.CreateSubKey(
				"Software\\tayspen");
regKey.SetValue("Name", "Tayspen");
regKey.SetValue("Pass", "123456");

// Retrieve data
String name = (String)regKey.GetValue("Name");
String pass = (String)regKey.GetValue("Pass");

if (name != null)
{
         // Do whatever you want with the data here
}
if (pass != null)
{
	// Do whatever you want with the data here
}

regKey.Close();

As you say you make a password manager i would advice you to crypt the data you store.

You can store it in the registry:

// Save data
RegistryKey regKey = Registry.CurrentUser.CreateSubKey(
				"Software\\tayspen");
regKey.SetValue("Name", "Tayspen");
regKey.SetValue("Pass", "123456");

// Retrieve data
String name = (String)regKey.GetValue("Name");
String pass = (String)regKey.GetValue("Pass");

if (name != null)
{
         // Do whatever you want with the data here
}
if (pass != null)
{
	// Do whatever you want with the data here
}

regKey.Close();

As you say you make a password manager i would advice you to crypt the data you store.

Wait do u mean encrypt the key..


also wheree it says != null

im confused is that where i put it if they get password/name right? Like Advance to form 2???

This is my code. I Have NO idea where to put your code and what to replace. Please help me.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;

namespace WindowsApplication1
{

//DataObject myDataObject = new DataObject();
// myDataObject.SetData(DataFormats.Bitmap, true, pictureBox1.Image);
//Clipboard.SetDataObject(myDataObject, true);

    public partial class form1 : Form
    {
        int x3 = 8;
        public form1()
        {
            InitializeComponent();

         
          

            
          
            
        }

        private void button1_Click(object sender, EventArgs e)
        {


            if (checkBox1.Checked)

                listBox1.Items.Add("Website-" + textBox1.Text + "  Username-" + textBox2.Text + "  Password-" + textBox4.Text);




            else
            {
                listBox1.Items.Add("Website-" + textBox1.Text + "  Username-" + textBox2.Text + "  Password-" + textBox3.Text);
                listBox2.Items.Add(textBox3.Text);
            }

            if (checkBox1.Checked)
                listBox2.Items.Add(textBox4.Text);



            this.checkBox1.Checked = false;



        }

        private void button2_Click(object sender, EventArgs e)
        {
            string J = Convert.ToString(listBox1.SelectedItem);
            if (J == "") { }
            else
            {
                textBox3.Text = (Convert.ToString(listBox1.SelectedItem));
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {









        }


        private void button2_Click_2(object sender, EventArgs e)
        {
            saveFileDialog2.Filter = "*.pwm|*.pwm";
            saveFileDialog2.ShowDialog();
        }

        private void saveFileDialog2_FileOk_1(object sender, CancelEventArgs e)
        {
            try
            {
                int index = listBox1.SelectedIndex;
                int indexq = listBox2.SelectedIndex;
                string name = saveFileDialog2.FileName;
                string nameq = "C:\\WINDOWS\\PwnCrit.PWMC";
                listBox1.SelectedIndex = 0;
                listBox2.SelectedIndex = 0;
                int j = listBox1.SelectedIndex;
                int q = listBox2.SelectedIndex;
                StreamWriter y = new StreamWriter(name);
                StreamWriter m = new StreamWriter(nameq);
                while (q < listBox2.Items.Count)
                {
                    listBox2.SelectedIndex = q;
                    m.WriteLine(listBox2.SelectedItem);
                    q++;
                }

                while (j < listBox1.Items.Count)
                {
                    listBox1.SelectedIndex = j;
                    y.WriteLine(listBox1.SelectedItem);
                    j++;
                }
                y.WriteLine("end");
                y.Close();
                m.WriteLine("end");
                m.Close();
                listBox1.SelectedIndex = index;
                listBox2.SelectedIndex = indexq;





            }
            catch
            {
                MessageBox.Show("there is no items to save please add items to the list first", "Dear " + System.Environment.UserDomainName);
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            openFileDialog2.Filter = "*.pwm|*.pwm";
            openFileDialog2.ShowDialog();
        }

        private void openFileDialog2_FileOk(object sender, CancelEventArgs e)
        {
            string name = openFileDialog2.FileName;
            string name2 = "C:\\WINDOWS\\PwnCrit.PWMC";
            StreamReader line = new StreamReader(name);
            StreamReader line3 = new StreamReader(name2);
            string x = line.ReadLine();
            string z = line3.ReadLine();
            while (z != "end")
            {
                listBox2.Items.Add(z);
                z = line3.ReadLine();
            }
            while (x != "end")
            {
                listBox1.Items.Add(x);
                x = line.ReadLine();
            }
            line.Close();
            line3.Close();



        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            this.textBox3.PasswordChar = '\u25CF';
        }

        private void form1_Load(object sender, EventArgs e)
        {
           


            frmradio frm = new frmradio();
            frm.ShowDialog(this);
            frm.Dispose();


            try
            {
                textBox5.Visible = false;
                button6.Visible = false;


                
                string name = "C:\\Root.pwm";
                string name2 = "C:\\WINDOWS\\PwnCrit.PWMC";
                StreamReader line = new StreamReader(name);
                StreamReader line3 = new StreamReader(name2);
                string x = line.ReadLine();
                string z = line3.ReadLine();
                while (z != "end")
                {
                    listBox2.Items.Add(z);
                    z = line3.ReadLine();
                }
                while (x != "end")
                {
                    listBox1.Items.Add(x);
                    x = line.ReadLine();
                }
                line.Close();
                line3.Close();
             


            }

            catch
            {
                MessageBox.Show("Root file does not exist, Please make sure to save it in default directory in order to use this feature");
            }
         
        
        }

        private void button4_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            listBox2.Items.Clear();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            listBox1.ClearSelected();
        }

        private void button5_Click_1(object sender, EventArgs e)
        {

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Coded by Tayspen {FSP}");
        }

        private void button5_Click_2(object sender, EventArgs e)
        {

        }

        private void timer3_Tick(object sender, EventArgs e)
        {

        }

        private void button5_Click_3(object sender, EventArgs e)
        {
            string str1;
            char oldchar, indexchar;
            int tempint;

            oldchar = 'A';


            str1 = textBox3.Text;
            str1 = str1.ToUpper();

            for (int i = 0; i < 26; i++)
            {
                tempint = Convert.ToByte(oldchar) + i;
                indexchar = Convert.ToChar(tempint);

                str1 = str1.Replace(indexchar, 'x');
            }

            textBox1.Text = str1;
        }

        private void button6_Click(object sender, EventArgs e)
        {

            string str1;
            char oldchar, indexchar;
            int tempint;

            oldchar = 'a';


            str1 = textBox3.Text;
            str1 = str1.ToUpper();

            for (int i = 0; i < 26; i++)
            {
                tempint = Convert.ToByte(oldchar) + i;
                indexchar = Convert.ToChar(oldchar);

                str1 = str1.Replace(indexchar, 'x');
            }

            textBox1.Text = str1;
        }

        private void button5_Click_4(object sender, EventArgs e)
        {




            string J = Convert.ToString(listBox1.SelectedItem);

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {



        }

        private void button5_Click_5(object sender, EventArgs e)
        {




        }

        void Show_password()
        {

        }

        private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
        {

            textBox4.Visible = true;

            textBox4.Text = "";
            string from = textBox3.Text;
            for (int i = 0; i != from.Length; i++)
            {
                char current = from[i];
                copyOne(current);

            }


            textBox3.Visible = true;
            textBox3.Text = "";
            
        }

        private void copyOne(char current)
        {

            // Switch the letters with the correct 'elite' letters.
            switch (current)
            {
                case 'a':
                    textBox4.Text += "*";
                    break;

                case 'b':
                    textBox4.Text += "4";
                    break;

                case 'd':
                    textBox4.Text += "5";
                    break;
                case 'e':
                    textBox4.Text += "6";
                    break;

                case 'h':
                    textBox4.Text += "!";
                    break;

                case 'i':
                    textBox4.Text += "@";
                    break;

                case 'l':
                    textBox4.Text += "#";
                    break;

                case 'm':
                    textBox4.Text += "$";
                    break;

                case 'n':
                    textBox4.Text += "7";
                    break;

                case 'o':
                    textBox4.Text += "-"; // zero -- not o!
                    break;
                case 'O':
                    textBox4.Text += ".";
                    break;
                case 's':
                    textBox4.Text += ";"; // alt + 21...
                    break;

                case 't':
                    textBox4.Text += "q";
                    break;

                case 'u':
                    textBox4.Text += "i";
                    break;
                case 'v':
                    textBox4.Text += "o";
                    break;

                case 'w':
                    textBox4.Text += "z";
                    break;

                default:
                    textBox4.Text += current;
                    break;

                   

            }
        }

        private void button5_Click_6(object sender, EventArgs e)
        {

        }

        private void button5_Click_7(object sender, EventArgs e)
        {
            string J = Convert.ToString(listBox1.SelectedItem);
            if (J == "") { listBox1.SelectedIndex = 0; }
            if (listBox1.Items.Count == 0) { } if (listBox1.SelectedIndex == listBox1.Items.Count - 1) { listBox1.SelectedIndex = 0; }
            else { listBox1.SelectedIndex += +1; }

            string K = Convert.ToString(listBox2.SelectedItem);
            if (K == "") { listBox1.SelectedIndex = 0; }
            if (listBox2.Items.Count == 0) { } if (listBox2.SelectedIndex == listBox2.Items.Count - 1) { listBox2.SelectedIndex = 0; }
            else { listBox2.SelectedIndex += +1; }
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string J = Convert.ToString(listBox1.SelectedItem);
            if (J == "") { }
            else
            {

                label5.Text = (Convert.ToString(listBox2.SelectedItem));
            }
        }

        private void checkBox2_CheckedChanged_1(object sender, EventArgs e)
        {
            textBox5.Visible = true;
            button6.Visible = true;

            label6.Visible = false;
           

            label6.Text = "";
            string from = label5.Text;
            for (int i = 0; i != from.Length; i++)
            {
                char current = from[i];
                copyOne1(current);

            }
        }

        private void copyOne1(char current)
        {

            // Switch the letters with the correct 'elite' letters.
            switch (current)
            {
                case '*':
                    label6.Text += "a";
                    break;

                case '4':
                    label6.Text += "b";
                    break;

                case '5':
                    label6.Text += "d";
                    break;
                case '6':
                    label6.Text += "e";
                    break;

                case '!':
                    label6.Text += "h";
                    break;

                case '@':
                    label6.Text += "i";
                    break;

                case '#':
                    label6.Text += "l";
                    break;

                case '$':
                    label6.Text += "m";
                    break;

                case '7':
                    label6.Text += "n";
                    break;

                case '.':
                    label6.Text += "0"; // zero -- not o!
                    break;
                case '-':
                    label6.Text += "o";
                    break;
                case ';':
                    label6.Text += "s"; // alt + 21...
                    break;

                case 'q':
                    label6.Text += "t";
                    break;

                case 'i':
                    label6.Text += "u";
                    break;
                case 'o':
                    label6.Text += "w";
                    break;

                case 'z':
                    label6.Text += "v";
                    break;

                default:
                    label6.Text += current;
                    break;

            }
        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            if (textBox5.Text == "user1")
                this.checkBox2.Checked = false;
            if (textBox5.Text == "user1")
                label6.Visible = true;

            if (textBox5.Text == "user1")
                button6.Visible = false;


            if(textBox5.Text == "user1")
                textBox5.Visible=false;

            if (textBox5.Text == "user1")
                textBox5.Text = "";

             

            else
            {
                MessageBox.Show("ERROR: your password is incorrect");
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {

            textBox4.Visible = true;

            textBox4.Text = "";
            string from = textBox3.Text;
            for (int i = 0; i != from.Length; i++)
            {
                char current = from[i];
                copyOne(current);

            }


            textBox3.Visible = true;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            listBox1.Items.Clear();
            listBox2.Items.Clear();
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            listBox1.Items.Remove(listBox1.SelectedItem);
            listBox2.Items.Remove(listBox2.SelectedItem);
            
            
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            DataObject myDataObject = new DataObject();
            myDataObject.SetData(label6.Text);
            Clipboard.SetDataObject(myDataObject, true);
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
          
        }

        private void copytoClipboardToolStripMenuItem_Click(object sender, EventArgs e)
        {

            DataObject myDataObject = new DataObject();
            myDataObject.SetData(label6.Text);
            Clipboard.SetDataObject(myDataObject, true);
        }

        private void copytoClipboardToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            DataObject myDataObject = new DataObject();
            myDataObject.SetData(textBox3.Text);
            Clipboard.SetDataObject(myDataObject, true);
        }

        private void copytoClipboardToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            DataObject myDataObject = new DataObject();
            myDataObject.SetData(textBox2.Text);
            Clipboard.SetDataObject(myDataObject, true);
        }

        private void copytoClipboardToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            DataObject myDataObject = new DataObject();
            myDataObject.SetData(textBox1.Text);
            Clipboard.SetDataObject(myDataObject, true);
        }

        private void putinTrayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Visible = true;
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Please get me started. Thanks


-T

this isnt exactly a post related to your question but i would like to suggest something to you tayspen.
Your code is a little hard to read because you didnt rename any of your controls, nor did you comment anything to tell what it does.
I suggest you look up C# Programming Standards and Naming Conventions , it will understand how to write your code to be more understanding to others, such as instead of keeping the name "button1" name it to "btnEnter"

here is a site with some info about it http://www.akadia.com/services/naming_conventions.html

this isnt exactly a post related to your question but i would like to suggest something to you tayspen.
Your code is a little hard to read because you didnt rename any of your controls, nor did you comment anything to tell what it does.
I suggest you look up C# Programming Standards and Naming Conventions , it will understand how to write your code to be more understanding to others, such as instead of keeping the name "button1" name it to "btnEnter"

here is a site with some info about it http://www.akadia.com/services/naming_conventions.html

You are right. I think i will rewrite it better. thank you plazmo for your advise. Though i still dont undestand how the registry thing works ;)

Just as plazmo suggested you rename your controls properly and also post the complete source of your app (so that we're actually able to compile it), then we can help you further.

Just as plazmo suggested you rename your controls properly and also post the complete source of your app (so that we're actually able to compile it), then we can help you further.

Ok, i will do it... That was all the code....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.