Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Dll to verfy username using linq to xml

magnetsofteesmagnetsoftees Posts: 7Member
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;
namespace loginlibrary
{
public class account
{
XDocument loginAccount;
XElement moreAccount;
public string folder;
public string getdirecotory()
{
string path = Directory.GetCurrentDirectory();
folder = path + "/" + "account.xml";
return folder;
}
public bool createAccount(string username,string password)
{
string folder = getdirecotory();
loginAccount=new XDocument(
new XElement("Staff",
new XElement("Account",
new XElement("username",username),
new XElement("password",password)
)
)
);

loginAccount.Save(folder);

return true;
}
public bool createMoreAccount(string username, string password)
{
string folder = getdirecotory();

XElement doc = XElement.Load(folder);

moreAccount =
new XElement("Account",
new XElement("username", username),
new XElement("password", password)
);

validate(username, password);


doc.Add(moreAccount);
doc.Save(folder);

return true;
}

public bool validate(string username, string password)
{

string folder = getdirecotory();

XElement doc = XElement.Load(folder);
XDocument docu = XDocument.Load(folder);

var user = from users in doc.Descendants("username") select users.Value;

// var pass = from passers in doc.Descendants("password") select passers.Value;
// var psser = from me in doc.Elements("Staff") select me.Value;


//var usergoodguy = from userguy in doc.Descendants("Staff").Elements("Account") where userguy.Element("username").Value == username select userguy.Value;

// foreach (var usernamee in user)
// {
if (user.Contains(username))
{

// return true;
// break;
//throw new Exception("cannot insert duplicate account");
}

else
{
return false;
// break;
}
// }
//foreach (var passee in pass)
//{
// if (passee == password)
// {
// // throw new Exception("cannot insert duplicate account");
// // return true;
// break;
// }
// else if (passee != password)
// {

// return false;
// // break;
// }
//}

//foreach (var go in psser)
//{
// if (go == username && go == password)
// {
// break;
// // return false;
// }
// else if(go!=username && go!=password)
// {
// return false;
// }
//}
return true;
}

public void dontDuplictate(string username, string password)
{
// Avoids Inserting Duplicate username.....
/*
* Avoids Inserting Duplicate username...
*/
string folder = getdirecotory();

XElement doc = XElement.Load(folder);
XDocument docu = XDocument.Load(folder);

var user = from users in doc.Descendants("username") select users.Value;

var pass = from passers in doc.Descendants("password") select passers.Value;
var psser = from me in doc.Elements("Staff") select me.Value;


var usergoodguy = from userguy in doc.Descendants("Staff").Elements("Account") where userguy.Element("username").Value == username select userguy.Value;

// foreach (var usernamee in user)
// {
if (user.Contains(username))
{

// return true;
// break;
throw new Exception("cannot insert duplicate account");
}

//else
//{
// return false;
// // break;
//}
// }
//foreach (var passee in pass)
//{
// if (passee == password)
// {
// // throw new Exception("cannot insert duplicate account");
// // return true;
// break;
// }
// else if (passee != password)
// {

// return false;
// // break;
// }
//}

//foreach (var go in psser)
//{
// if (go == username && go == password)
// {
// break;
// // return false;
// }
// else if(go!=username && go!=password)
// {
// return false;
// }
//}

}


}

}

Sign In or Register to comment.