Working towards validating the username and password
This commit is contained in:
parent
8f4270a1ce
commit
0911479d22
@ -310,6 +310,8 @@ namespace EduNetworkBuilder
|
|||||||
public static int UntaggedVLAN = -1; //If the packet is not tagged.
|
public static int UntaggedVLAN = -1; //If the packet is not tagged.
|
||||||
public static int MaxPacketsBeforeOptimizing = 50;
|
public static int MaxPacketsBeforeOptimizing = 50;
|
||||||
|
|
||||||
|
public static string AllowedPasswordCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!~@#$%^&*()_+{}[]/?<>,.";
|
||||||
|
public static string AllowedUsernameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890._";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Find the global random number generator.
|
/// Find the global random number generator.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -896,6 +898,22 @@ namespace EduNetworkBuilder
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
public static bool ValidateString(string tovalidate, string AllowedCharacters)
|
||||||
|
{
|
||||||
|
if (tovalidate == null || tovalidate == "") return false;
|
||||||
|
if (AllowedCharacters == null || AllowedCharacters == "") return false;
|
||||||
|
foreach (char one in tovalidate)
|
||||||
|
if (!AllowedCharacters.Contains(one)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public static bool ValidatePassword(string password)
|
||||||
|
{
|
||||||
|
return ValidateString(password, AllowedPasswordCharacters);
|
||||||
|
}
|
||||||
|
public static bool ValidateUsername(string password)
|
||||||
|
{
|
||||||
|
return ValidateString(password, AllowedUsernameCharacters);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
EduNetworkBuilder/PersonProfileForm.Designer.cs
generated
1
EduNetworkBuilder/PersonProfileForm.Designer.cs
generated
@ -177,6 +177,7 @@
|
|||||||
this.btnImportStudents.TabIndex = 0;
|
this.btnImportStudents.TabIndex = 0;
|
||||||
this.btnImportStudents.Text = "Import Students";
|
this.btnImportStudents.Text = "Import Students";
|
||||||
this.btnImportStudents.UseVisualStyleBackColor = true;
|
this.btnImportStudents.UseVisualStyleBackColor = true;
|
||||||
|
this.btnImportStudents.Click += new System.EventHandler(this.btnImportStudents_Click);
|
||||||
//
|
//
|
||||||
// TabHomework
|
// TabHomework
|
||||||
//
|
//
|
||||||
|
@ -8,9 +8,20 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Microsoft.VisualBasic.FileIO; //for CSV parsing
|
||||||
|
|
||||||
namespace EduNetworkBuilder
|
namespace EduNetworkBuilder
|
||||||
{
|
{
|
||||||
|
//A temporary holding structure when loading in students from CSV for validation.
|
||||||
|
//Once loaded and parsed, we then make actual students from them.
|
||||||
|
class StudentHolder
|
||||||
|
{
|
||||||
|
public string Name = "";
|
||||||
|
public string Password = "";
|
||||||
|
public string FullName = "";
|
||||||
|
public bool ForceToChangePass = true;
|
||||||
|
}
|
||||||
|
|
||||||
public partial class PersonProfileForm : Form
|
public partial class PersonProfileForm : Form
|
||||||
{
|
{
|
||||||
enum TopTab { profiletab=0, classworktab=1}
|
enum TopTab { profiletab=0, classworktab=1}
|
||||||
@ -378,5 +389,48 @@ namespace EduNetworkBuilder
|
|||||||
Close(); //Exit out of the profile
|
Close(); //Exit out of the profile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnImportStudents_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//Get a csv file
|
||||||
|
//try to read it in
|
||||||
|
//Import them all
|
||||||
|
OpenFileDialog mydialog = new OpenFileDialog();
|
||||||
|
mydialog.AddExtension = true;
|
||||||
|
string filter = "Comma Separated List (*.csv)|*.csv";
|
||||||
|
mydialog.Filter = filter;
|
||||||
|
mydialog.Multiselect = false;
|
||||||
|
mydialog.CheckFileExists = true;
|
||||||
|
mydialog.ShowHelp = true;
|
||||||
|
if (CurrentUser.UserSettings.LastPath != null && CurrentUser.UserSettings.LastPath != "")
|
||||||
|
mydialog.FileName = CurrentUser.UserSettings.LastPath;
|
||||||
|
DialogResult result = mydialog.ShowDialog();
|
||||||
|
if (result == System.Windows.Forms.DialogResult.Cancel) return;
|
||||||
|
|
||||||
|
List<StudentHolder> tList = new List<StudentHolder>();
|
||||||
|
|
||||||
|
//Now we have a csv file. Try to parse it
|
||||||
|
using (TextFieldParser parser = new TextFieldParser(mydialog.FileName))
|
||||||
|
{
|
||||||
|
parser.TextFieldType = FieldType.Delimited;
|
||||||
|
parser.SetDelimiters(",");
|
||||||
|
while (!parser.EndOfData)
|
||||||
|
{
|
||||||
|
//Process row
|
||||||
|
int index = 0;
|
||||||
|
string[] fields = parser.ReadFields();
|
||||||
|
StudentHolder TStudent = new StudentHolder();
|
||||||
|
foreach (string field in fields)
|
||||||
|
{
|
||||||
|
//TODO: Process field
|
||||||
|
if (index == 0) TStudent.Name = field;
|
||||||
|
if (index == 1) TStudent.FullName = field;
|
||||||
|
if (index == 2) TStudent.Password = field;
|
||||||
|
index++; //Track which field we are in.
|
||||||
|
}
|
||||||
|
tList.Add(TStudent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user