Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Security Login Xml file
 

Security Login Xml file

hihi.help needed urgent(using visual c#)

my form is able to display data grid for xml file but is there any code which can actually make certain portion of the information shown as a password format(***).

how do i able to allow in window application to actually to be able to edit the data in the xml form(edit the data in xml,delete and reset details in xml or even save inforation in it)?

code for my xml file

<?xml version="1.0" encoding="utf-8" ?>
<users>
<user>
<Name>Bob</Name>
<Password>pass</Password>
<Role>Administrator</Role>
</user>
<user>
<Name>John</Name>
<Password>pass</Password>
<Role>Operator</Role>

</user>
</users>

code for diplaying the details in window application

private void UserRolesAndPrivileges_Load(object sender, EventArgs e)

{

if ((Thread.CurrentPrincipal.IsInRole("Administrator")))

{

// Grab list of Users

DataSet dsUsers = new DataSet();

dsUsers.ReadXml(@"..\..\users.xml");

// Bind the list of users to the Grid and display

dgUsers.CaptionText = "User Accounts";

dgUsers.DataSource = dsUsers.Tables[0];

}

else

{

MessageBox.Show("You must be a member of the Manager or Administrator's roles to " +

"view username and password information", "Insufficient Permissions",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

intoxicated-  Wednesday, November 07, 2007 12:48 AM

Hi intoxicated-,

I recommend you use a DataGridView instead of DataGrid. It is very easy to set the password column display �***� You just need to handle the CellFormatting event. Here is a sample for your information:

Code Block

DataGridP

public partial class DGXML : Form

{

public DGXML()

{

InitializeComponent();

}

DataSet dsUsers = new DataSet();

private void DGXML_Load(object sender, EventArgs e)

{

if ((Thread.CurrentPrincipal.IsInRole("Administrator")))

{

// Grab list of Users

dsUsers.ReadXml(@"C:\1.xml");

// Bind the list of users to the Grid and display

dgUsers.CaptionText = "User Accounts";

dgUsers.DataSource = dsUsers.Tables[0];

this.dataGridView1.DataSource = dgUsers.DataSource = dsUsers.Tables[0];

this.dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);

}

else

{

MessageBox.Show("You must be a member of the Manager or Administrator's roles to " + "view username and password information", "Insufficient Permissions",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

{

if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Password")

{

e.Value = "******";

}

}

private void btnSave_Click(object sender, EventArgs e)

{//save to the data to xml file

dsUsers.WriteXml(@"C:\1.xml", XmlWriteMode.WriteSchema);

}

}

To let the user edit in the DataGridView and write back to the XML file, you need the DataSet.WriteXml method. Check the above code sample.

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Tuesday, November 13, 2007 2:11 PM

Hi intoxicated-,

I recommend you use a DataGridView instead of DataGrid. It is very easy to set the password column display �***� You just need to handle the CellFormatting event. Here is a sample for your information:

Code Block

DataGridP

public partial class DGXML : Form

{

public DGXML()

{

InitializeComponent();

}

DataSet dsUsers = new DataSet();

private void DGXML_Load(object sender, EventArgs e)

{

if ((Thread.CurrentPrincipal.IsInRole("Administrator")))

{

// Grab list of Users

dsUsers.ReadXml(@"C:\1.xml");

// Bind the list of users to the Grid and display

dgUsers.CaptionText = "User Accounts";

dgUsers.DataSource = dsUsers.Tables[0];

this.dataGridView1.DataSource = dgUsers.DataSource = dsUsers.Tables[0];

this.dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);

}

else

{

MessageBox.Show("You must be a member of the Manager or Administrator's roles to " + "view username and password information", "Insufficient Permissions",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

{

if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Password")

{

e.Value = "******";

}

}

private void btnSave_Click(object sender, EventArgs e)

{//save to the data to xml file

dsUsers.WriteXml(@"C:\1.xml", XmlWriteMode.WriteSchema);

}

}

To let the user edit in the DataGridView and write back to the XML file, you need the DataSet.WriteXml method. Check the above code sample.

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Tuesday, November 13, 2007 2:11 PM

hi

as what i have know the code actually change the whole column of password to asterix including empty boxes how to i able to wwrite a code to compare if only boxes wth values under the password section will change to asterix

as for the edit save and edit the xml right i am not very sure which to use as in stream?string or? any samples ? sorrie for he inconvience causes

intoxicated-  Wednesday, November 14, 2007 3:50 PM

Hi intoxicated-,

The code I gave was not changed the password column to asterisk, but format the column to display asterisk. You still can see the actual password in the dataset.

As for saving data back to the XML file, why not use the DataSet.WriteXml method. It is easy to handle.

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Thursday, November 15, 2007 2:43 AM

yups i got it already but the xml i am trying to do need to be able to select the ros and reset the password column and be able to save it to the default file foler itself

the msdn shows there is

DataSet.WriteXml method (stream)

DataSet.WriteXml method(string) and more which one is advisable to use and whats the difference

intoxicated-  Thursday, November 15, 2007 6:42 AM

You can use google to search for other answers

Custom Search

More Threads

• Terrariom Down?
• Installation Failure
• Download sample windows application projects
• Defect in MainForm.MainForm_Load()
• What exactly is the Peer Channel?
• Sample code not working in VB.NET ???
• Draw in graph?
• Programically selecting an item in DataGridComboBoxCell
• problem with the update of the IssueVision
• Install Task Vision Server in a Domain