944,139 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 11810
  • C# RSS
Sep 4th, 2005
0

XML save settings

Expand Post »
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.
Similar Threads
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 5th, 2005
0

Re: XML save settings

You can store it in the registry:

C# Syntax (Toggle Plain Text)
  1. // Save data
  2. RegistryKey regKey = Registry.CurrentUser.CreateSubKey(
  3. "Software\\tayspen");
  4. regKey.SetValue("Name", "Tayspen");
  5. regKey.SetValue("Pass", "123456");
  6.  
  7. // Retrieve data
  8. String name = (String)regKey.GetValue("Name");
  9. String pass = (String)regKey.GetValue("Pass");
  10.  
  11. if (name != null)
  12. {
  13. // Do whatever you want with the data here
  14. }
  15. if (pass != null)
  16. {
  17. // Do whatever you want with the data here
  18. }
  19.  
  20. regKey.Close();

As you say you make a password manager i would advice you to crypt the data you store.
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003
Sep 5th, 2005
0

Re: XML save settings

Quote originally posted by r0ckbaer ...
You can store it in the registry:

C# Syntax (Toggle Plain Text)
  1. // Save data
  2. RegistryKey regKey = Registry.CurrentUser.CreateSubKey(
  3. "Software\\tayspen");
  4. regKey.SetValue("Name", "Tayspen");
  5. regKey.SetValue("Pass", "123456");
  6.  
  7. // Retrieve data
  8. String name = (String)regKey.GetValue("Name");
  9. String pass = (String)regKey.GetValue("Pass");
  10.  
  11. if (name != null)
  12. {
  13. // Do whatever you want with the data here
  14. }
  15. if (pass != null)
  16. {
  17. // Do whatever you want with the data here
  18. }
  19.  
  20. 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???
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 5th, 2005
0

Re: XML save settings

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


C# Syntax (Toggle Plain Text)
  1.  
  2. using System;
  3. using System.Drawing;
  4. using System.Collections;
  5. using System.ComponentModel;
  6. using System.Windows.Forms;
  7. using System.Data;
  8. using System.IO;
  9. using System.Runtime.InteropServices;
  10. using System.Security;
  11. using System.Security.Cryptography;
  12. using System.Text;
  13.  
  14. namespace WindowsApplication1
  15. {
  16.  
  17. //DataObject myDataObject = new DataObject();
  18. // myDataObject.SetData(DataFormats.Bitmap, true, pictureBox1.Image);
  19. //Clipboard.SetDataObject(myDataObject, true);
  20.  
  21. public partial class form1 : Form
  22. {
  23. int x3 = 8;
  24. public form1()
  25. {
  26. InitializeComponent();
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. }
  35.  
  36. private void button1_Click(object sender, EventArgs e)
  37. {
  38.  
  39.  
  40. if (checkBox1.Checked)
  41.  
  42. listBox1.Items.Add("Website-" + textBox1.Text + " Username-" + textBox2.Text + " Password-" + textBox4.Text);
  43.  
  44.  
  45.  
  46.  
  47. else
  48. {
  49. listBox1.Items.Add("Website-" + textBox1.Text + " Username-" + textBox2.Text + " Password-" + textBox3.Text);
  50. listBox2.Items.Add(textBox3.Text);
  51. }
  52.  
  53. if (checkBox1.Checked)
  54. listBox2.Items.Add(textBox4.Text);
  55.  
  56.  
  57.  
  58. this.checkBox1.Checked = false;
  59.  
  60.  
  61.  
  62. }
  63.  
  64. private void button2_Click(object sender, EventArgs e)
  65. {
  66. string J = Convert.ToString(listBox1.SelectedItem);
  67. if (J == "") { }
  68. else
  69. {
  70. textBox3.Text = (Convert.ToString(listBox1.SelectedItem));
  71. }
  72. }
  73.  
  74. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  75. {
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. }
  86.  
  87.  
  88. private void button2_Click_2(object sender, EventArgs e)
  89. {
  90. saveFileDialog2.Filter = "*.pwm|*.pwm";
  91. saveFileDialog2.ShowDialog();
  92. }
  93.  
  94. private void saveFileDialog2_FileOk_1(object sender, CancelEventArgs e)
  95. {
  96. try
  97. {
  98. int index = listBox1.SelectedIndex;
  99. int indexq = listBox2.SelectedIndex;
  100. string name = saveFileDialog2.FileName;
  101. string nameq = "C:\\WINDOWS\\PwnCrit.PWMC";
  102. listBox1.SelectedIndex = 0;
  103. listBox2.SelectedIndex = 0;
  104. int j = listBox1.SelectedIndex;
  105. int q = listBox2.SelectedIndex;
  106. StreamWriter y = new StreamWriter(name);
  107. StreamWriter m = new StreamWriter(nameq);
  108. while (q < listBox2.Items.Count)
  109. {
  110. listBox2.SelectedIndex = q;
  111. m.WriteLine(listBox2.SelectedItem);
  112. q++;
  113. }
  114.  
  115. while (j < listBox1.Items.Count)
  116. {
  117. listBox1.SelectedIndex = j;
  118. y.WriteLine(listBox1.SelectedItem);
  119. j++;
  120. }
  121. y.WriteLine("end");
  122. y.Close();
  123. m.WriteLine("end");
  124. m.Close();
  125. listBox1.SelectedIndex = index;
  126. listBox2.SelectedIndex = indexq;
  127.  
  128.  
  129.  
  130.  
  131.  
  132. }
  133. catch
  134. {
  135. MessageBox.Show("there is no items to save please add items to the list first", "Dear " + System.Environment.UserDomainName);
  136. }
  137.  
  138. }
  139.  
  140. private void button3_Click(object sender, EventArgs e)
  141. {
  142.  
  143. openFileDialog2.Filter = "*.pwm|*.pwm";
  144. openFileDialog2.ShowDialog();
  145. }
  146.  
  147. private void openFileDialog2_FileOk(object sender, CancelEventArgs e)
  148. {
  149. string name = openFileDialog2.FileName;
  150. string name2 = "C:\\WINDOWS\\PwnCrit.PWMC";
  151. StreamReader line = new StreamReader(name);
  152. StreamReader line3 = new StreamReader(name2);
  153. string x = line.ReadLine();
  154. string z = line3.ReadLine();
  155. while (z != "end")
  156. {
  157. listBox2.Items.Add(z);
  158. z = line3.ReadLine();
  159. }
  160. while (x != "end")
  161. {
  162. listBox1.Items.Add(x);
  163. x = line.ReadLine();
  164. }
  165. line.Close();
  166. line3.Close();
  167.  
  168.  
  169.  
  170. }
  171.  
  172. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  173. {
  174. this.textBox3.PasswordChar = '\u25CF';
  175. }
  176.  
  177. private void form1_Load(object sender, EventArgs e)
  178. {
  179.  
  180.  
  181.  
  182. frmradio frm = new frmradio();
  183. frm.ShowDialog(this);
  184. frm.Dispose();
  185.  
  186.  
  187. try
  188. {
  189. textBox5.Visible = false;
  190. button6.Visible = false;
  191.  
  192.  
  193.  
  194. string name = "C:\\Root.pwm";
  195. string name2 = "C:\\WINDOWS\\PwnCrit.PWMC";
  196. StreamReader line = new StreamReader(name);
  197. StreamReader line3 = new StreamReader(name2);
  198. string x = line.ReadLine();
  199. string z = line3.ReadLine();
  200. while (z != "end")
  201. {
  202. listBox2.Items.Add(z);
  203. z = line3.ReadLine();
  204. }
  205. while (x != "end")
  206. {
  207. listBox1.Items.Add(x);
  208. x = line.ReadLine();
  209. }
  210. line.Close();
  211. line3.Close();
  212.  
  213.  
  214.  
  215. }
  216.  
  217. catch
  218. {
  219. MessageBox.Show("Root file does not exist, Please make sure to save it in default directory in order to use this feature");
  220. }
  221.  
  222.  
  223. }
  224.  
  225. private void button4_Click(object sender, EventArgs e)
  226. {
  227. listBox1.Items.Clear();
  228. listBox2.Items.Clear();
  229. }
  230.  
  231. private void button5_Click(object sender, EventArgs e)
  232. {
  233. listBox1.ClearSelected();
  234. }
  235.  
  236. private void button5_Click_1(object sender, EventArgs e)
  237. {
  238.  
  239. }
  240.  
  241. private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  242. {
  243. Application.Exit();
  244. }
  245.  
  246. private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  247. {
  248. MessageBox.Show("Coded by Tayspen {FSP}");
  249. }
  250.  
  251. private void button5_Click_2(object sender, EventArgs e)
  252. {
  253.  
  254. }
  255.  
  256. private void timer3_Tick(object sender, EventArgs e)
  257. {
  258.  
  259. }
  260.  
  261. private void button5_Click_3(object sender, EventArgs e)
  262. {
  263. string str1;
  264. char oldchar, indexchar;
  265. int tempint;
  266.  
  267. oldchar = 'A';
  268.  
  269.  
  270. str1 = textBox3.Text;
  271. str1 = str1.ToUpper();
  272.  
  273. for (int i = 0; i < 26; i++)
  274. {
  275. tempint = Convert.ToByte(oldchar) + i;
  276. indexchar = Convert.ToChar(tempint);
  277.  
  278. str1 = str1.Replace(indexchar, 'x');
  279. }
  280.  
  281. textBox1.Text = str1;
  282. }
  283.  
  284. private void button6_Click(object sender, EventArgs e)
  285. {
  286.  
  287. string str1;
  288. char oldchar, indexchar;
  289. int tempint;
  290.  
  291. oldchar = 'a';
  292.  
  293.  
  294. str1 = textBox3.Text;
  295. str1 = str1.ToUpper();
  296.  
  297. for (int i = 0; i < 26; i++)
  298. {
  299. tempint = Convert.ToByte(oldchar) + i;
  300. indexchar = Convert.ToChar(oldchar);
  301.  
  302. str1 = str1.Replace(indexchar, 'x');
  303. }
  304.  
  305. textBox1.Text = str1;
  306. }
  307.  
  308. private void button5_Click_4(object sender, EventArgs e)
  309. {
  310.  
  311.  
  312.  
  313.  
  314. string J = Convert.ToString(listBox1.SelectedItem);
  315.  
  316. }
  317.  
  318. private void checkBox2_CheckedChanged(object sender, EventArgs e)
  319. {
  320.  
  321.  
  322.  
  323. }
  324.  
  325. private void button5_Click_5(object sender, EventArgs e)
  326. {
  327.  
  328.  
  329.  
  330.  
  331. }
  332.  
  333. void Show_password()
  334. {
  335.  
  336. }
  337.  
  338. private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
  339. {
  340.  
  341. textBox4.Visible = true;
  342.  
  343. textBox4.Text = "";
  344. string from = textBox3.Text;
  345. for (int i = 0; i != from.Length; i++)
  346. {
  347. char current = from[i];
  348. copyOne(current);
  349.  
  350. }
  351.  
  352.  
  353. textBox3.Visible = true;
  354. textBox3.Text = "";
  355.  
  356. }
  357.  
  358. private void copyOne(char current)
  359. {
  360.  
  361. // Switch the letters with the correct 'elite' letters.
  362. switch (current)
  363. {
  364. case 'a':
  365. textBox4.Text += "*";
  366. break;
  367.  
  368. case 'b':
  369. textBox4.Text += "4";
  370. break;
  371.  
  372. case 'd':
  373. textBox4.Text += "5";
  374. break;
  375. case 'e':
  376. textBox4.Text += "6";
  377. break;
  378.  
  379. case 'h':
  380. textBox4.Text += "!";
  381. break;
  382.  
  383. case 'i':
  384. textBox4.Text += "@";
  385. break;
  386.  
  387. case 'l':
  388. textBox4.Text += "#";
  389. break;
  390.  
  391. case 'm':
  392. textBox4.Text += "$";
  393. break;
  394.  
  395. case 'n':
  396. textBox4.Text += "7";
  397. break;
  398.  
  399. case 'o':
  400. textBox4.Text += "-"; // zero -- not o!
  401. break;
  402. case 'O':
  403. textBox4.Text += ".";
  404. break;
  405. case 's':
  406. textBox4.Text += ";"; // alt + 21...
  407. break;
  408.  
  409. case 't':
  410. textBox4.Text += "q";
  411. break;
  412.  
  413. case 'u':
  414. textBox4.Text += "i";
  415. break;
  416. case 'v':
  417. textBox4.Text += "o";
  418. break;
  419.  
  420. case 'w':
  421. textBox4.Text += "z";
  422. break;
  423.  
  424. default:
  425. textBox4.Text += current;
  426. break;
  427.  
  428.  
  429.  
  430. }
  431. }
  432.  
  433. private void button5_Click_6(object sender, EventArgs e)
  434. {
  435.  
  436. }
  437.  
  438. private void button5_Click_7(object sender, EventArgs e)
  439. {
  440. string J = Convert.ToString(listBox1.SelectedItem);
  441. if (J == "") { listBox1.SelectedIndex = 0; }
  442. if (listBox1.Items.Count == 0) { } if (listBox1.SelectedIndex == listBox1.Items.Count - 1) { listBox1.SelectedIndex = 0; }
  443. else { listBox1.SelectedIndex += +1; }
  444.  
  445. string K = Convert.ToString(listBox2.SelectedItem);
  446. if (K == "") { listBox1.SelectedIndex = 0; }
  447. if (listBox2.Items.Count == 0) { } if (listBox2.SelectedIndex == listBox2.Items.Count - 1) { listBox2.SelectedIndex = 0; }
  448. else { listBox2.SelectedIndex += +1; }
  449. }
  450.  
  451. private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
  452. {
  453. string J = Convert.ToString(listBox1.SelectedItem);
  454. if (J == "") { }
  455. else
  456. {
  457.  
  458. label5.Text = (Convert.ToString(listBox2.SelectedItem));
  459. }
  460. }
  461.  
  462. private void checkBox2_CheckedChanged_1(object sender, EventArgs e)
  463. {
  464. textBox5.Visible = true;
  465. button6.Visible = true;
  466.  
  467. label6.Visible = false;
  468.  
  469.  
  470. label6.Text = "";
  471. string from = label5.Text;
  472. for (int i = 0; i != from.Length; i++)
  473. {
  474. char current = from[i];
  475. copyOne1(current);
  476.  
  477. }
  478. }
  479.  
  480. private void copyOne1(char current)
  481. {
  482.  
  483. // Switch the letters with the correct 'elite' letters.
  484. switch (current)
  485. {
  486. case '*':
  487. label6.Text += "a";
  488. break;
  489.  
  490. case '4':
  491. label6.Text += "b";
  492. break;
  493.  
  494. case '5':
  495. label6.Text += "d";
  496. break;
  497. case '6':
  498. label6.Text += "e";
  499. break;
  500.  
  501. case '!':
  502. label6.Text += "h";
  503. break;
  504.  
  505. case '@':
  506. label6.Text += "i";
  507. break;
  508.  
  509. case '#':
  510. label6.Text += "l";
  511. break;
  512.  
  513. case '$':
  514. label6.Text += "m";
  515. break;
  516.  
  517. case '7':
  518. label6.Text += "n";
  519. break;
  520.  
  521. case '.':
  522. label6.Text += "0"; // zero -- not o!
  523. break;
  524. case '-':
  525. label6.Text += "o";
  526. break;
  527. case ';':
  528. label6.Text += "s"; // alt + 21...
  529. break;
  530.  
  531. case 'q':
  532. label6.Text += "t";
  533. break;
  534.  
  535. case 'i':
  536. label6.Text += "u";
  537. break;
  538. case 'o':
  539. label6.Text += "w";
  540. break;
  541.  
  542. case 'z':
  543. label6.Text += "v";
  544. break;
  545.  
  546. default:
  547. label6.Text += current;
  548. break;
  549.  
  550. }
  551. }
  552.  
  553. private void button6_Click_1(object sender, EventArgs e)
  554. {
  555. if (textBox5.Text == "user1")
  556. this.checkBox2.Checked = false;
  557. if (textBox5.Text == "user1")
  558. label6.Visible = true;
  559.  
  560. if (textBox5.Text == "user1")
  561. button6.Visible = false;
  562.  
  563.  
  564. if(textBox5.Text == "user1")
  565. textBox5.Visible=false;
  566.  
  567. if (textBox5.Text == "user1")
  568. textBox5.Text = "";
  569.  
  570.  
  571.  
  572. else
  573. {
  574. MessageBox.Show("ERROR: your password is incorrect");
  575. }
  576. }
  577.  
  578. private void button7_Click(object sender, EventArgs e)
  579. {
  580.  
  581. textBox4.Visible = true;
  582.  
  583. textBox4.Text = "";
  584. string from = textBox3.Text;
  585. for (int i = 0; i != from.Length; i++)
  586. {
  587. char current = from[i];
  588. copyOne(current);
  589.  
  590. }
  591.  
  592.  
  593. textBox3.Visible = true;
  594. }
  595.  
  596. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  597. {
  598. listBox1.Items.Clear();
  599. listBox2.Items.Clear();
  600. }
  601.  
  602. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  603. {
  604. listBox1.Items.Remove(listBox1.SelectedItem);
  605. listBox2.Items.Remove(listBox2.SelectedItem);
  606.  
  607.  
  608. }
  609.  
  610. private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  611. {
  612.  
  613. DataObject myDataObject = new DataObject();
  614. myDataObject.SetData(label6.Text);
  615. Clipboard.SetDataObject(myDataObject, true);
  616. }
  617.  
  618. private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
  619. {
  620.  
  621. }
  622.  
  623. private void copytoClipboardToolStripMenuItem_Click(object sender, EventArgs e)
  624. {
  625.  
  626. DataObject myDataObject = new DataObject();
  627. myDataObject.SetData(label6.Text);
  628. Clipboard.SetDataObject(myDataObject, true);
  629. }
  630.  
  631. private void copytoClipboardToolStripMenuItem1_Click(object sender, EventArgs e)
  632. {
  633. DataObject myDataObject = new DataObject();
  634. myDataObject.SetData(textBox3.Text);
  635. Clipboard.SetDataObject(myDataObject, true);
  636. }
  637.  
  638. private void copytoClipboardToolStripMenuItem2_Click(object sender, EventArgs e)
  639. {
  640. DataObject myDataObject = new DataObject();
  641. myDataObject.SetData(textBox2.Text);
  642. Clipboard.SetDataObject(myDataObject, true);
  643. }
  644.  
  645. private void copytoClipboardToolStripMenuItem3_Click(object sender, EventArgs e)
  646. {
  647. DataObject myDataObject = new DataObject();
  648. myDataObject.SetData(textBox1.Text);
  649. Clipboard.SetDataObject(myDataObject, true);
  650. }
  651.  
  652. private void putinTrayToolStripMenuItem_Click(object sender, EventArgs e)
  653. {
  654. this.Visible = false;
  655. }
  656.  
  657. private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
  658. {
  659. this.Visible = true;
  660. }
  661.  
  662. private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
  663. {
  664. Application.Exit();
  665. }
  666. }
  667. }

Please get me started. Thanks


-T
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 5th, 2005
0

Re: XML save settings

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
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Sep 5th, 2005
0

Re: XML save settings

Quote originally posted by plazmo ...
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
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 5th, 2005
0

Re: XML save settings

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.
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003
Sep 5th, 2005
0

Re: XML save settings

Quote originally posted by r0ckbaer ...
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....
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: File.Create Question
Next Thread in C# Forum Timeline: Crystal report with condition in C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC