Exemplo n.º 1
0
        protected void Create_Chain_User_Click(object sender, EventArgs e)
        {
            userDetails udTest = BackEndObjects.userDetails.getUserDetailsbyIdDB(TextBox1.Text);

            if (udTest.getUserId() == null || udTest.getUserId().Equals("")) //New user id
            {
                userDetails uD = new userDetails();
                uD.setMainEntityId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());

                Random ranGen         = new Random();
                int    saltInt        = ranGen.Next(1, 16);
                byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes((TextBox2.Text.Equals("") ? TextBox2.Attributes["password"] : TextBox2.Text)
                                                                           + saltInt);
                HashAlgorithm hashConverter    = new SHA256Managed();
                byte[]        hashedByteStream = hashConverter.ComputeHash(plainTextBytes);
                String        encryptedAndConvertedPassword = Convert.ToBase64String(hashedByteStream);

                uD.setSubEntityId(DropDownList1.SelectedValue);
                uD.setUserId(TextBox1.Text);
                uD.setPassword(encryptedAndConvertedPassword);
                uD.setSalt(saltInt.ToString());
                uD.setName(TextBox_User_Name_NewAccount.Text);

                Dictionary <String, userDetails> userList = MainBusinessEntity.getUserDetailsforMainEntitybyIdDB(uD.getMainEntityId());
                if (userList.ContainsKey(uD.getUserId()))
                {
                    Label2.Visible   = true;
                    Label2.ForeColor = System.Drawing.Color.Red;
                    Label2.Text      = "This user account is already created for your organization";
                }
                else
                {
                    ArrayList uDChains = new ArrayList();
                    uDChains.Add(uD);
                    ActionLibrary.RegistrationActions regstr = new RegistrationActions();
                    try
                    {
                        regstr.completeRegr(uDChains);
                        Label2.Visible   = true;
                        Label2.ForeColor = System.Drawing.Color.Green;
                        Label2.Text      = "Account created successfully";
                    }
                    catch (Exception ex)
                    {
                        Label2.Visible   = true;
                        Label2.ForeColor = System.Drawing.Color.Red;
                        Label2.Text      = "Account creation failed";
                    }
                }
            }
            else
            {
                Label2.Visible   = true;
                Label2.ForeColor = System.Drawing.Color.Red;
                Label2.Text      = "User Id is not available..please choose another one";
            }
        }