Fix login con plain pwd

This commit is contained in:
Samuele E. Locatelli
2019-09-27 21:58:06 +02:00
parent 14ea55ab4b
commit c12d596ce2
6 changed files with 173 additions and 131 deletions
@@ -8,7 +8,7 @@
DataTextField="label" DataValueField="value">
</asp:DropDownList>
<asp:ObjectDataSource ID="odsDipendenti" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="GPW_data.DS_UtilityTableAdapters.v_selDipendentiTableAdapter">
SelectMethod="getAttivi" TypeName="GPW_data.DS_UtilityTableAdapters.v_selDipendentiTableAdapter">
</asp:ObjectDataSource>
<br />
<label for="UserAuthKey">
@@ -9,104 +9,119 @@ using GPW_data;
namespace GPW.WebUserControls
{
public partial class mod_enrollByAuthKey : System.Web.UI.UserControl
public partial class mod_enrollByAuthKey : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// salvo nuovo device...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnConferma_Click(object sender, EventArgs e)
}
/// <summary>
/// salvo nuovo device...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnConferma_Click(object sender, EventArgs e)
{
// controllo se ho i dati...
string plainUserAuthKey = txtUserAuthKey.Text.Trim();
// in primis cerco il dipendente data la authKey...
int idxDipendente = 0;
try
{
idxDipendente = Convert.ToInt32(ddlIdxDipendente.SelectedValue);
}
catch
{ }
try
{
// controllo dipendente... che sia selezionato uno valido
if (idxDipendente > 0)
{
// controllo se ho i dati...
string plainUserAuthKey = txtUserAuthKey.Text.Trim();
// in primis cerco il dipendente data la authKey...
int idxDipendente = 0;
// dichiarazione variabili
string userAgent = "";
bool fatto = false;
string DeviceName = "";
string IPv4 = "";
string md5UserAuthKey = "";
int trovate = 0;
try
{
// recupero dati da session
userAgent = Request.UserAgent;
DeviceName = Request.UserHostName;
IPv4 = Request.UserHostName;
}
catch
{
logger.lg.scriviLog("Errore recupero dati da sessione x user, device, IP", tipoLog.ERROR);
}
// calcolo authKey... cerco se ne trovo x utente encrypted o unencrypted
md5UserAuthKey = SteamCrypto.EncryptString(plainUserAuthKey, "AuthGPW");
logger.lg.scriviLog(string.Format("Richiesta auth smart device per idxDipendente {0} con key MD5 {1}", idxDipendente, md5UserAuthKey), tipoLog.INFO);
int trovatePlain = 0;
int trovateMd5 = 0;
try
{
trovateMd5 = DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, md5UserAuthKey).Rows.Count;
trovatePlain = DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, plainUserAuthKey).Rows.Count;
trovate = trovatePlain + trovateMd5;
}
catch
{
logger.lg.scriviLog("Errore ricerca key in chiaro/MD5 x utente", tipoLog.ERROR);
}
if (trovate > 0)
{
try
{
idxDipendente = Convert.ToInt32(ddlIdxDipendente.SelectedValue);
}
catch
{ }
try
{
// controllo dipendente... che sia selezionato uno valido
if (idxDipendente > 0)
{
// dichiarazione variabili
string userAgent = "";
bool fatto = false;
string DeviceName = "";
string IPv4 = "";
string md5UserAuthKey = "";
int trovate = 0;
try
{
// recupero dati da session
userAgent = Request.UserAgent;
DeviceName = Request.UserHostName;
IPv4 = Request.UserHostName;
}
catch
{
logger.lg.scriviLog("Errore recupero dati da sessione x user, device, IP", tipoLog.ERROR);
}
// calcolo authKey... cerco se ne trovo x utente encrypted o unencrypted
md5UserAuthKey = SteamCrypto.EncryptString(plainUserAuthKey, "AuthGPW");
logger.lg.scriviLog(string.Format("Richiesta auth smart device per idxDipendente {0} con key MD5 {1}", idxDipendente, md5UserAuthKey), tipoLog.INFO);
try
{
trovate = DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, md5UserAuthKey).Rows.Count + DataProxy.DP.taDipendenti.getByAuthKey(idxDipendente, plainUserAuthKey).Rows.Count;
}
catch
{
logger.lg.scriviLog("Errore ricerca key in chiaro/MD5 x utente", tipoLog.ERROR);
}
if (trovate > 0)
{
try
{
fatto = DataProxy.DP.enrollDevice(md5UserAuthKey, IPv4, DeviceName, userAgent, idxDipendente);
if (fatto)
{
Response.Redirect("~/Timbrature.aspx");
}
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in registrazione nuovo device con AuthKey CIFRATA x utente: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
else
{
lblWarning.Text = "AuthKey non trovata! richiedere reset ad Admin.";
lblWarning.Visible = true;
}
}
else
{
lblWarning.Text = "Dipendente non trovato!";
lblWarning.Visible = true;
}
if (trovateMd5 > 0)
{
fatto = DataProxy.DP.enrollDevice(md5UserAuthKey, IPv4, DeviceName, userAgent, idxDipendente);
}
else if (trovatePlain > 0)
{
fatto = DataProxy.DP.enrollDevice(plainUserAuthKey, IPv4, DeviceName, userAgent, idxDipendente);
}
if (fatto)
{
Response.Redirect("~/Timbrature.aspx");
}
else
{
}
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in registrazione device: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
logger.lg.scriviLog(string.Format("Errore in registrazione nuovo device con AuthKey CIFRATA x utente: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
else
{
lblWarning.Text = "AuthKey non trovata! richiedere reset ad Admin.";
lblWarning.Visible = true;
}
}
/// <summary>
/// resetto tutto
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAnnulla_Click(object sender, EventArgs e)
else
{
txtUserAuthKey.Text = "";
lblWarning.Text = "Dipendente non trovato!";
lblWarning.Visible = true;
}
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in registrazione device: {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
/// <summary>
/// resetto tutto
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAnnulla_Click(object sender, EventArgs e)
{
txtUserAuthKey.Text = "";
}
}
}
+23 -23
View File
@@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// <generato automaticamente>
// Codice generato da uno strumento.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// Le modifiche a questo file possono causare un comportamento non corretto e verranno perse se
// il codice viene rigenerato.
// </generato automaticamente>
//------------------------------------------------------------------------------
namespace GPW.WebUserControls {
@@ -13,56 +13,56 @@ namespace GPW.WebUserControls {
public partial class mod_enrollByAuthKey {
/// <summary>
/// ddlIdxDipendente control.
/// Controllo ddlIdxDipendente.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList ddlIdxDipendente;
/// <summary>
/// odsDipendenti control.
/// Controllo odsDipendenti.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.ObjectDataSource odsDipendenti;
/// <summary>
/// txtUserAuthKey control.
/// Controllo txtUserAuthKey.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtUserAuthKey;
/// <summary>
/// lblWarning control.
/// Controllo lblWarning.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.Label lblWarning;
/// <summary>
/// btnConferma control.
/// Controllo btnConferma.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnConferma;
/// <summary>
/// btnAnnulla control.
/// Controllo btnAnnulla.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// Campo generato automaticamente.
/// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind.
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnAnnulla;
}