Esempio n. 1
0
        public JsonResult DeleteRow(string r)
        {
            string rowDeleted = "false";

            if (Session["userid"] != null)
            {
                if (Session["userid"].ToString().Trim() != "")
                {
                    using (var ctx = new PasswordManagerEntities())
                    {
                        var recordToDelete = ctx.Password.SingleOrDefault(x => x.ID.ToString() == r);
                        if (recordToDelete != null)
                        {
                            ctx.Password.Remove(recordToDelete);
                            ctx.SaveChanges();
                            rowDeleted = "true";
                        }
                        else
                        {
                            rowDeleted = "false";
                        }
                    }
                }
            }
            return(Json(new { rowisdeleted = rowDeleted }));
        }
        //GET api/Passwords/5
        public IHttpActionResult Get(int id)
        {
            if (id <= 0)
            {
                return(BadRequest(ErrorMsg.InvalidId));
            }
            string   userId   = User.Identity.GetUserId();
            Password password = db.Passwords.FirstOrDefault(w => w.Id == id && w.UserId == userId);//get the current password from user

            if (password is null)
            {
                return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.Password))); //check if that exists
            }
            password.NumOfVisits++;                                                  //modify when is last visited
            db.SaveChanges();                                                        //save the changes
            return(Ok(new PasswordVM(password)));                                    //send
        }
Esempio n. 3
0
        public IHttpActionResult Get(int id)
        {
            if (id <= 0)
            {
                return(BadRequest(ErrorMsg.InvalidId));
            }
            string      userId      = User.Identity.GetUserId();
            PaymentCard paymentCard = db.PaymentCards.FirstOrDefault(n => n.Id == id && n.UserId == userId);

            if (paymentCard is null)
            {
                return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.PaymentCard)));
            }
            paymentCard.NumOfVisits++;
            db.SaveChanges();
            return(Ok(new PaymentCardVM(paymentCard)));
        }
Esempio n. 4
0
        //GET api/Notes/5
        public IHttpActionResult Get(int id)
        {
            if (id <= 0)
            {
                return(BadRequest(ErrorMsg.InvalidId));
            }
            string userId = User.Identity.GetUserId();
            Note   note   = db.Notes.FirstOrDefault(n => n.Id == id && n.UserId == userId);

            if (note is null)
            {
                return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.Note)));
            }
            note.NumOfVisits++;
            db.SaveChanges();
            return(Ok(new NoteVM(note)));
        }
        //GET api/Wifis/5
        public IHttpActionResult Get(int id)
        {
            if (id <= 0)
            {
                return(BadRequest(ErrorMsg.InvalidId));
            }
            string userId = User.Identity.GetUserId();
            //get current wifi based on userId
            Wifi wifi = db.Wifis.FirstOrDefault(w => w.Id == id && w.UserId == userId);

            if (wifi is null)
            {
                return(BadRequest(ErrorMsg.ItemDoesNotExist(TypeOfItems.Wifi)));
            }
            wifi.NumOfVisits++;
            db.SaveChanges();
            return(Ok(new WifiVM(wifi)));
        }
Esempio n. 6
0
        public JsonResult RegisterNewUser(string firstname, string lastname, string username, string upassword, string pHash)
        {
            //https://msdn.microsoft.com/en-us/library/system.security.cryptography.aes(v=vs.110).aspx
            string authsuccess = "false";

            try
            {
                string original = upassword;

                // Create a new instance of the Aes
                // class.  This generates a new key and initialization
                // vector (IV).
                using (Aes myAes = Aes.Create())
                {
                    byte[] arrayk = Encoding.ASCII.GetBytes(pHash);
                    myAes.Key = arrayk;

                    byte[] IVmy = myAes.IV;
                    // Encrypt the string to an array of bytes.
                    byte[] encrypted = EncryptStringToBytes_Aes(original, arrayk, IVmy);

                    // var encryptedPwd = System.Text.Encoding.Default.GetString(encrypted);
                    var strpwdIV = System.Text.Encoding.Default.GetString(IVmy);
                    try
                    {
                        PasswordManagerEntities db   = new PasswordManagerEntities();
                        PasswordManager.User    user = new PasswordManager.User
                        {
                            FirstName   = firstname.Trim(),
                            LastName    = lastname.Trim(),
                            UserName    = username.Trim(),
                            UPasswrd    = encrypted,
                            UPassHash   = pHash.Trim(),
                            UPassIVHash = IVmy
                        };

                        db.User.Add(user);
                        db.SaveChanges();
                        authsuccess = "true";
                    }
                    catch (Exception exp)
                    {
                    }

                    // Decrypt the bytes to a string.
                    //string roundtrip = DecryptStringFromBytes_Aes(encrypted,myAes.Key, myAes.IV);
                }
            }
            catch (Exception e)
            {
            }

            return(Json(new { regsuccess = authsuccess }));
        }
Esempio n. 7
0
        public JsonResult UpdateRow(string w, string u, string p, string r, string h)
        {
            string rowUpdated = "false";

            if (Session["userid"] != null)
            {
                if (Session["userid"].ToString().Trim() != "")
                {
                    string original = p;

                    // Create a new instance of the Aes
                    // class.  This generates a new key and initialization
                    // vector (IV).
                    using (Aes myAes = Aes.Create())
                    {
                        byte[] arrayk = Encoding.ASCII.GetBytes(h);
                        myAes.Key = arrayk;

                        byte[] IVmy = myAes.IV;
                        // Encrypt the string to an array of bytes.
                        byte[] encrypted = EncryptStringToBytes_Aes(original, arrayk, IVmy);

                        // var encryptedPwd = System.Text.Encoding.Default.GetString(encrypted);
                        var strpwdIV = System.Text.Encoding.Default.GetString(IVmy);
                        try
                        {
                            using (PasswordManagerEntities PasswordManagerEntities = new PasswordManagerEntities())
                            {
                                var ur = (from q in PasswordManagerEntities.Password
                                          where (q.ID.ToString() == r.Trim())
                                          select q).SingleOrDefault();

                                ur.Website        = w.Trim();
                                ur.UserName       = u.Trim();
                                ur.Password1      = encrypted;
                                ur.PasswordHash   = h.Trim();
                                ur.PasswordIVHash = IVmy;

                                PasswordManagerEntities.SaveChanges();

                                rowUpdated = "true";
                            }
                        }
                        catch (Exception exp)
                        {
                        }
                        // Decrypt the bytes to a string.
                        //string roundtrip = DecryptStringFromBytes_Aes(encrypted,myAes.Key, myAes.IV);
                    }
                }
            }

            return(Json(new { rowisupdated = rowUpdated }));
        }
Esempio n. 8
0
        public JsonResult AddNewPassword(string w, string u, string p, string h)
        {
            string addnewpwdsuccess = "false";

            try
            {
                string original = p;

                // Create a new instance of the Aes
                // class.  This generates a new key and initialization
                // vector (IV).
                using (Aes myAes = Aes.Create())
                {
                    byte[] arrayk = Encoding.ASCII.GetBytes(h);
                    myAes.Key = arrayk;

                    byte[] IVmy = myAes.IV;
                    // Encrypt the string to an array of bytes.
                    byte[] encrypted = EncryptStringToBytes_Aes(original, arrayk, IVmy);

                    // var encryptedPwd = System.Text.Encoding.Default.GetString(encrypted);
                    var strpwdIV = System.Text.Encoding.Default.GetString(IVmy);
                    try
                    {
                        PasswordManagerEntities  db     = new PasswordManagerEntities();
                        PasswordManager.Password passwd = new PasswordManager.Password
                        {
                            UserID         = Convert.ToInt32(Session["userid"].ToString()),
                            Website        = w.Trim(),
                            UserName       = u.Trim(),
                            Password1      = encrypted,
                            PasswordHash   = h.Trim(),
                            PasswordIVHash = IVmy
                        };

                        db.Password.Add(passwd);
                        db.SaveChanges();
                        addnewpwdsuccess = "true";
                    }
                    catch (Exception exp)
                    {
                    }
                    // Decrypt the bytes to a string.
                    //string roundtrip = DecryptStringFromBytes_Aes(encrypted,myAes.Key, myAes.IV);
                }
            }
            catch (Exception e)
            {
            }
            return(Json(new { addnewpasswordstatus = addnewpwdsuccess }));
        }