Howdy, Stranger!

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

Categories

Dll to verfy username using linq to xml

magnetsofteesmagnetsoftees Member Posts: 7
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.