Add Method LogonUserWithOTP in Authenticator WebService

Open the code editor of AuthenticatorService.svc.cs and add a reference to OTPSharedProject that was created earlier.

using OTPSharedProject;

We add the code for LogonUserWithOTP as follows:

public string LogonUserWithOTP(string theLogin, string thePassword, int TheOTP)
{

string anIdentifier;
Guid aGuid;
string myMessage;

try
{

using (SqlConnection MyConnection = new SqlConnection(myConnectionString))
{

using (SqlCommand cmd = new SqlCommand(“dbo.LoginUser”, MyConnection))
{

cmd.CommandType = CommandType.StoredProcedure;
//Create and add a parameter to Parameters collection for the stored procedure.
cmd.Parameters.Add(new SqlParameter(“@TheLogin”, SqlDbType.NVarChar, 255));
cmd.Parameters.Add(new SqlParameter(“@ThePassword”, SqlDbType.NVarChar, 32));
//Create and add an output parameter to the Parameters collection.
cmd.Parameters.Add(new SqlParameter(“@Identifier”, SqlDbType.UniqueIdentifier));cmd.Parameters.Add(new SqlParameter(“@ResponseMessage”, SqlDbType.NVarChar, 128));

//Set the direction for the parameter.
cmd.Parameters[“@Identifier”].Direction = ParameterDirection.Output;
cmd.Parameters[“@ResponseMessage”].Direction = ParameterDirection.Output;
//Assign the input values to the parameter.
cmd.Parameters[“@TheLogin”].Value = (theLogin).Trim();
cmd.Parameters[“@ThePassword”].Value = (thePassword).Trim();
MyConnection.Open();
cmd.ExecuteNonQuery();

anIdentifier = cmd.Parameters[“@Identifier”].Value.ToString();
aGuid = new Guid(anIdentifier);

if (!OTPAuthenticator.IsValidOTPFromGuid(aGuid, TheOTP))
{

//Not a successful login
myMessage = “Bad OTP”;

}

else
{

myMessage = cmd.Parameters[“@ResponseMessage”].Value.ToString();

}

}

}

}

catch (Exception ex)
{

myMessage = ex.Message;

}

return myMessage;

}

 

 

Advertisements

Post a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s