C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Dll to verfy username using linq to xml Posted by magnetsoftees on 18 Aug 2012 at 10:48 AM
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;
// }
//}

}


}

}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.