NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using Dapper;
using IPUTILITY.Extensions;
using IPUTILITY.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace IPUTILITY.Controllers
{
public class UserController : Controller
{
public static int EncrKey { get; set; }
public string MobileNo { get; private set; }
public string ServiceId { get; private set; }

public string Decrypt(string textToDecrypt)
{
StringBuilder inSb = new StringBuilder(textToDecrypt);
StringBuilder outSb = new StringBuilder(textToDecrypt.Length);
char c;
for (int i = 0; i < textToDecrypt.Length; i++)
{
c = inSb[i];
c = (char)(c ^ EncrKey);
outSb.Append(c);
}
return outSb.ToString();
}
// GET: User
public ActionResult Login()
{
EncrKey = new Random().Next(256, 500);
ViewData["RanNum"] = EncrKey;



return View();
}

//public static string Encrypt(string plaintext, string password)
//{
// //string plaintext = "Hello world!";
// password = "mypassword";

// byte[] salt = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };

// RijndaelManaged aes = new RijndaelManaged();
// aes.BlockSize = 128;
// aes.KeySize = 256;
// aes.Padding = PaddingMode.PKCS7;

// var key = new Rfc2898DeriveBytes(password,salt, 1000);
// aes.Key = key.GetBytes(aes.KeySize / 8);
// aes.IV = key.GetBytes(aes.BlockSize / 8);

// ICryptoTransform encryptor = aes.CreateEncryptor();

// byte[] plaintextBytes = Encoding.UTF8.GetBytes(plaintext);
// byte[] encryptedBytes = encryptor.TransformFinalBlock(plaintextBytes, 0, plaintextBytes.Length);

// Console.WriteLine(Convert.ToBase64String(encryptedBytes));
// return Convert.ToBase64String(encryptedBytes);
//}

public static string Encrypt(string value, string key, string iv)
{
byte[] keyBytes = Convert.FromBase64String(key);
byte[] ivBytes = Convert.FromBase64String(iv);
byte[] valueBytes = Encoding.UTF8.GetBytes(value);

using (var aes = new AesManaged())
{
aes.KeySize = 128;
aes.BlockSize = 128;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
aes.Key = keyBytes;
aes.IV = ivBytes;

using (var encryptor = aes.CreateEncryptor())
{
byte[] encryptedBytes = encryptor.TransformFinalBlock(valueBytes, 0, valueBytes.Length);
return Convert.ToBase64String(encryptedBytes);
}
}
}





public ActionResult ValidateLogin(string UserId, string Password)
{
try
{



string decryptUserId = Decrypt(UserId);
string decryptPwd = Decrypt(Password);

// string IPaddress = Utility.GetIPAddress();
// Random r = new Random();
// string OTP = r.Next(1000, 9999).ToString();

// //Send message

//string number = "8779582137";


//DataTable dtUserCheck = new DataTable();

using (SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["SPMConnection"]))
{
using (SqlCommand cmd = new SqlCommand())
{
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.CommandText = "USP_IPO_VALIDATE_USER_LOGIN";
//cmd.Connection = sqlconn;
////cmd.Parameters.AddWithValue("@Mode", "Login");
//cmd.Parameters.AddWithValue("@UserID", decryptUserId);
//cmd.Parameters.AddWithValue("@UserPwd", decryptPwd);
//cmd.Parameters.AddWithValue("@UserIPAddress", IPaddress);
//cmd.CommandTimeout = 0;

//using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
//{
// sda.Fill(dtUserCheck);
//}
ManagedAesSample obj = new ManagedAesSample();
List<UserLoginControl> UserNameInUse = SqlMapper.Query<UserLoginControl>(sqlconn, "USP_INV_VALIDATE_USER_LOGIN").ToList();
var UserData = UserNameInUse.Find(x => x.UserID.Equals(decryptUserId));
if (decryptUserId == UserData.UserID && decryptPwd == obj.Decrypt(UserData.Password) && UserData.IsActive == true)
{
resetattempt(UserData.UserID);

Session["SPM_USERID"] = Convert.ToString(UserData.UserID); //Convert.ToString(dtUserCheck.Rows[0]["UserID"]);
string s = Session["SPM_USERID"].ToString();
Session["SPM_USERNAME"] = UserData.UserName;// Convert.ToString(dtUserCheck.Rows[0]["UserName"]);
string guid = Guid.NewGuid().ToString();
Session["SPMAuthToken"] = guid;
HttpCookie vboAuthToken = new HttpCookie("SPMAuthToken", guid);
vboAuthToken.HttpOnly = true;

string EncryptStatus = "1";
string key = "sphc73103SPHCMPI";

string systemtime = DateTime.Now.ToString("MM/dd/yyyy h:mm tt");

///string time = AESEncryptionProvider.Encrypt(key, systemtime);



EncryptStatus = AESEncryptionProvider.Encrypt(key, EncryptStatus + '|' + systemtime);


string EncryptMessage = AESEncryptionProvider.Encrypt(key, "/IPUTILITY/Home" + '|' + systemtime);




return Json(new { Status = EncryptStatus, Message = EncryptMessage });
}
else if (UserData.IsActive == false)
{
string message = "Your account has been locked. Contact your support person to unlock it, then try again";
return Json(new { Status = "0", Message = message });



}
else
{
string message = "Please Enter Valide Username & Password..";
return Json(new { Status = "0", Message = message });
}

}
}

//if (dtUserCheck != null && dtUserCheck.Rows.Count > 0)
//{
// if (Convert.ToString(dtUserCheck.Rows[0]["Status"]) == "1" && Convert.ToString(dtUserCheck.Rows[0]["LockStatus"]) != "1")
// {
// Session["SPM_USERID"] = Convert.ToString(dtUserCheck.Rows[0]["UserID"]);
// Session["SPM_USERNAME"] = Convert.ToString(dtUserCheck.Rows[0]["UserName"]);
// string guid = Guid.NewGuid().ToString();
// Session["SPMAuthToken"] = guid;
// HttpCookie vboAuthToken = new HttpCookie("SPMAuthToken", guid);
// vboAuthToken.HttpOnly = true;

// Response.Cookies.Add(vboAuthToken);
// // Response.Cookies["SPMAuthToken"].Secure = true;
// //Response.Cookies["ASP.NET_SessionId"].Secure = true;

// return Json(new { Status = "1", Message = "/IPUTILITY/Home" });
// }
// else
// if (Convert.ToString(dtUserCheck.Rows[0]["LockStatus"]) == "1")
// {
// string message = "Your account has been locked. Contact your support person to unlock it, then try again";
// return Json(new { Status = "0", Message = message });
// }
// else
// {
// int MaxAttempts = 0;
// int num = 0;

// if (Convert.ToString(dtUserCheck.Rows[0]["Status"]) == "0")
// {
// MaxAttempts++;

// }
// if ((((int?)Session["UserLock"] ?? 0) == 0))
// {
// Session["UserLock"] = MaxAttempts;
// }
// else
// {
// Session["UserLock"] = Convert.ToInt32(Session["UserLock"]) + 1;
// }
// num = Convert.ToInt32(Session["UserLock"]);
// if (num == 3)
// {
// LockAccount(decryptUserId, decryptPwd);
// string message = "Your account has been locked. Contact your support person to unlock it, then try again";
// return Json(new { Status = "0", Message = message });
// }
// else
// {
// string message = Convert.ToString(dtUserCheck.Rows[0]["Message"]);
// return Json(new { Status = "0", Message = message });
// }

// }
//}
//else

}
catch (Exception ex)
{
// ErrorLogger.LogErrorToFile(Session["SPM_USERID"], this.ControllerContext, ex);
ErrorMaster.ErrorLog(Session["SPM_USERID"], this.ControllerContext, ex);
return Json(new { Status = "0", Message = "Something went wrong at runtime!!" });
}
}



public void LockAccount(string userid, string decryptPwd)
{
try
{
DataSet dsDbResponse = new DataSet();

using (SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["SPMConnection"]))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "USP_IPO_UPDATE_ACCOUNT";
cmd.Connection = sqlconn;
cmd.CommandTimeout = 0;
cmd.Parameters.AddWithValue("@Mode", "LockAccount");
cmd.Parameters.AddWithValue("@UserID", userid);
cmd.Parameters.AddWithValue("@UserPwd", decryptPwd);
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dsDbResponse);
}
}
}
}
catch (Exception ex)
{
//ErrorLogger.LogErrorToFile(Session["SPM_USERID"], this.ControllerContext, ex);
ErrorMaster.ErrorLog(Session["SPM_USERID"], this.ControllerContext, ex);
}
}
public ActionResult SessionExpired()
{
return View();
}
//otp changes start here
public void resetattempt(string userid)
{
try
{
DataSet dsDbResponse = new DataSet();

using (SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["SPMConnection"]))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "USP_update_User_attempt";
cmd.Connection = sqlconn;
cmd.CommandTimeout = 0;
cmd.Parameters.AddWithValue("@Userid", userid);

using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dsDbResponse);
}
}
}
}
catch (Exception ex)
{
//ErrorLogger.LogErrorToFile(Session["SPM_USERID"], this.ControllerContext, ex);
ErrorMaster.ErrorLog(Session["SPM_USERID"], this.ControllerContext, ex);
}
}
//public static string GetLocalIPAddress()
//{
// var host = Dns.GetHostEntry(Dns.GetHostName());
// foreach (var ip in host.AddressList)
// {
// if (ip.AddressFamily == AddressFamily.InterNetwork)
// {
// return ip.ToString();
// }
// }
// throw new Exception("No network adapters with an IPv4 address in the system!");
//}

public static string GetIPAddress()
{
HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (!string.IsNullOrEmpty(ipAddress))
{
string[] addresses = ipAddress.Split(',');
if (addresses.Length != 0)
{
return addresses[0];
}
}

return context.Request.ServerVariables["REMOTE_ADDR"];
}

public ActionResult GETOTP(string otptype)
{


if (Session["SPM_USERID"] != null)
{
String userid = Session["SPM_USERID"].ToString();

Random r = new Random();
string OTP = r.Next(1000, 9999).ToString();
string source = "IPUTILITY";


//string source = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
string IP_Address = GetIPAddress();
HttpRequest req = System.Web.HttpContext.Current.Request;
string DEVICE_VERSION = req.Browser.Browser + req.Browser.Version;
String RequestedUserType = "EMP";

//HttpBrowserCapabilities browser = request.Browser;
//string browserName = browser.Browser;
//string browserVersion = req.Browser.Version;

//string message = "Dear T022975,your one-time password for MO Investor is 708481. This OTP is valid for 30 Minutes, Team Motilal Oswal. K/mWDahPC1K";


DataTable dt = new DataTable();
using (SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["SPMConnection"]))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "USP_OTP_PROCESS";
cmd.Connection = sqlconn;
cmd.Parameters.AddWithValue("@USERID", userid);
cmd.Parameters.AddWithValue("@otp", OTP);
cmd.Parameters.AddWithValue("@otptype", otptype);
cmd.Parameters.AddWithValue("@SOURCE", source);
cmd.Parameters.AddWithValue("@RequestedUserType", RequestedUserType);
cmd.Parameters.AddWithValue("@IP_address", IP_Address);
cmd.Parameters.AddWithValue("@DEVICE_VERSION", DEVICE_VERSION);

//cmd.Parameters.AddWithValue("@DEVICE_VERSION", browserVersion);
//cmd.Parameters.AddWithValue("@Email", Email);
//cmd.Parameters.AddWithValue("@Mobile_no", phone);

cmd.CommandTimeout = 0;

using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
//var Message = cmd.Parameters["@message"].Value.ToString();

}

}


}


if (dt.Rows.Count >= 0)
{
//string Message = dt.Rows[0]["message"].ToString();
////ViewBag.message = Message;

string key = "sphc73103SPHCMPI";

string systemtime = DateTime.Now.ToString("dddd , MMM dd yyyy,hh:mm:ss");

///string time = AESEncryptionProvider.Encrypt(key, systemtime);

string EncryptvalidStatus = dt.Rows[0]["Status"].ToString();

EncryptvalidStatus = AESEncryptionProvider.Encrypt(key, EncryptvalidStatus + '|' + systemtime);









return Json(new { Status = EncryptvalidStatus, Message = dt.Rows[0]["message"] });
}



}
else
{
return Json(new
{
Status = "-1",
Message = "/login"
});
}


return View();
}





public ActionResult VAlidateotp(string otpvalidate)
{
string decryptotpvalidate = Decrypt(otpvalidate);


if (Session["SPM_USERID"] != null)
{
String userid = Session["SPM_USERID"].ToString();





DataTable dsDbResponse = new DataTable();
using (SqlConnection sqlconn = new SqlConnection(ConfigurationManager.AppSettings["SPMConnection"]))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "ValidateOTP";
cmd.Connection = sqlconn;
cmd.Parameters.AddWithValue("@USERID", userid);
cmd.Parameters.AddWithValue("@otp", decryptotpvalidate);

//cmd.Parameters.AddWithValue("@Email", Email);
//cmd.Parameters.AddWithValue("@Mobile_no", phone);

cmd.CommandTimeout = 0;

using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dsDbResponse);

//string a= dsDbResponse.Rows[0]["ISVALID"].ToString();


}
}


}
string key = ConfigurationManager.AppSettings["Key"].ToString();

string systemtime = DateTime.Now.ToString("dddd , MMM dd yyyy,hh:mm:ss");

//string time = AESEncryptionProvider.Encrypt(key, systemtime);

string EncryptvalidStatus = dsDbResponse.Rows[0]["Status"].ToString();

EncryptvalidStatus = AESEncryptionProvider.Encrypt(key, EncryptvalidStatus + '|' + systemtime);

// string validdata = EncryptvalidStatus + '|' + time;

string path = "/UTILITY/IPUTILITY/Home";


string EncryptvalidMessage = AESEncryptionProvider.Encrypt(key, path + '|' + systemtime);

//string validmessage = EncryptvalidMessage + '|' + time;





//if (EncryptvalidStatus == "1")
//{
return Json(new { Status = EncryptvalidStatus, Message = EncryptvalidMessage });

//}
//else
//{
// return Json(new { Status = dsDbResponse.Rows[0]["Status"], Message = dsDbResponse.Rows[0]["message"] });
//}
}
else
{
string userstatus = ConfigurationManager.AppSettings["userstat"].ToString();
string key = ConfigurationManager.AppSettings["Key"].ToString();
string systemtime = DateTime.Now.ToString("MM/dd/yyyy h:mm tt");

String usermessage = ConfigurationManager.AppSettings["login"].ToString();

string encryuserstatus = AESEncryptionProvider.Encrypt(key, userstatus + '|' + systemtime);

string encryusermessage = AESEncryptionProvider.Encrypt(key, usermessage + '|' + systemtime);


return Json(new
{
Status = encryuserstatus,
Message = encryusermessage
});
}


//return View();
}


//otp changes end here


}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.