ln.skyscanner/crawl/CredentialsGenerator.cs

68 lines
1.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
namespace ln.skyscanner.crawl
{
public class CredentialsGenerator : IEnumerable<Credential>
{
HashSet<String> userNames = new HashSet<string>();
HashSet<String> passWords = new HashSet<string>();
public CredentialsGenerator()
{
}
public CredentialsGenerator AddUserNames(IEnumerable<string> usernames)
{
foreach (String userName in usernames)
AddUserName(userName);
return this;
}
public CredentialsGenerator AddUserName(String username)
{
userNames.Add(username);
return this;
}
public CredentialsGenerator AddPasswords(IEnumerable<string> passwords)
{
foreach (String pw in passwords)
AddPassword(pw);
return this;
}
public CredentialsGenerator AddPassword(String password)
{
passWords.Add(password);
return this;
}
public IEnumerator<Credential> GetEnumerator()
{
foreach (String username in userNames)
foreach (String pw in passWords)
yield return new Credential(username, pw);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public class Credential
{
public String Username { get; }
public String Password { get; }
public Credential(String username,String password)
{
Username = username;
Password = password;
}
}
}