Exemplo n.º 1
0
        public ActionResult PreenchePerfil(Aluno a)
        {
            var CurrentID = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                Aluno f = context.Alunos.Single(x => x.UserId == CurrentID);

                f.Nome      = a.Nome;
                f.nAluno    = a.nAluno;
                f.Curriculo = a.Curriculo;
                f.Ramo      = a.Ramo;
            }
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult SubmitE(Proposta s)
        {
            var     CurrentID = User.Identity.GetUserId();
            Empresa emp       = context.Empresas.Single(x => x.UserId == CurrentID);

            if (ModelState.IsValid)
            {
                if (emp.Nome == null)
                {
                    return(RedirectToAction("../Home/PerfilIncompleto"));
                }

                s.Livre    = true;
                s.Student  = null;
                s.Empresas = emp;
                emp.Propostas.Add(s);
            }
            context.SaveChanges();
            return(RedirectToAction("../Home/Submetido"));
        }
Exemplo n.º 3
0
        //  [Authorize(Roles = "Empresa")]
        public ActionResult PreenchePerfil(Empresa a)
        {
            var CurrentID = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                Empresa f = context.Empresas.Single(x => x.UserId == CurrentID);

                f.Nome      = a.Nome;
                f.Telefone  = a.Telefone;
                f.Propostas = null;
            }
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public void AddPassword(string username, byte[] encryptionKey, string tag, string password){
            using (var db = new TP1Context())
            {   
                var data = from u in db.Users where u.Username == username select u;
                User user = data.FirstOrDefault();
                
                using (var aesAlg = Aes.Create())
                {
                    using (var encryptor = aesAlg.CreateEncryptor(encryptionKey, aesAlg.IV))
                    {
                        using (var msEncrypt = new MemoryStream())
                        {
                            using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                            using (var swEncrypt = new StreamWriter(csEncrypt))
                            {
                                swEncrypt.Write(password);
                            }

                            var iv = aesAlg.IV;

                            var decryptedContent = msEncrypt.ToArray();

                            var result = new byte[iv.Length + decryptedContent.Length];

                            Buffer.BlockCopy(iv, 0, result, 0, iv.Length);
                            Buffer.BlockCopy(decryptedContent, 0, result, iv.Length, decryptedContent.Length);

                            string base64Password = Convert.ToBase64String(result);
                            db.Passwords.Add(new Password(){
                                SavedPassword = base64Password,
                                User = user,
                                UserId = user.UserID,
                                Tag = tag
                            });

                            if(db.SaveChanges() == 1){
                                System.Console.WriteLine("OK");
                            }else{
                                System.Console.WriteLine("Error id DB save");
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public bool Register(string username, string masterPassword){
            using (var db = new TP1Context())
            {
                var data = from u in db.Users where u.Username == username select u;
                User user = data.FirstOrDefault();

                if(user != null){
                    System.Console.WriteLine("User already exists");
                    return false;
                }
                
                byte[] salt = new byte[128 / 8];  

                using(var keyGenerator = RandomNumberGenerator.Create())  
                {  
                    keyGenerator.GetBytes(salt);  
                    string encodedSalt = Convert.ToBase64String(salt);
                    using(var sha256 = SHA256.Create())  
                    {  
                        // Send a sample text to hash.  
                        byte[] passwordBytes = System.Text.Encoding.Unicode.GetBytes(masterPassword);
                        
                        byte[] encodedBytes = new byte[passwordBytes.Length + salt.Length];
                        passwordBytes.CopyTo(encodedBytes, 0);
                        salt.CopyTo(encodedBytes,passwordBytes.Length);

                        var hashedBytes = sha256.ComputeHash(encodedBytes);  
                        string encodedTxt = Convert.ToBase64String(encodedBytes);
                        user = new User(){
                            Username= username,
                            Password= encodedTxt,
                            Salt=encodedSalt,
                        };
                        db.Users.Add(user);
                        return db.SaveChanges() == 1;
                    }  
                }  
            }
        }
Exemplo n.º 6
0
        public void DeletePassword(string username, string tag){
            using (var db = new TP1Context())
            {   
                var data = db.Users.Include(u => u.SavedPassword).Where(u => u.Username == username);
                User user = data.FirstOrDefault();
                
                if(user == null || user.SavedPassword == null){
                    System.Console.WriteLine("Password does not exist");
                    return;
                }

                Password pwd = user.SavedPassword.Where(p => p.Tag == tag).FirstOrDefault();

                if(pwd == null){
                    System.Console.WriteLine("Password does not exist");
                    return;
                }

                db.Passwords.Remove(pwd);
                db.SaveChanges();
                System.Console.WriteLine("OK");
            }
        }