---
id: "7dc7440b-1221-46fc-87a2-d376bf5b0a81"
name: c-form-username-and-password-validation-838939c27d36
description: "Validates username and password inputs in a C# Windows Form based on specific length, complexity, and alphanumeric constraints."
version: "0.1.0"
tags:
  - "C#"
  - "Windows Forms"
  - "Validation"
  - "Password Policy"
  - "Regex"
triggers:
  - "validate username and password"
  - "apply password validation rules"
  - "check password length and case"
  - "alphanumeric username validation"
  - "C# form input validation"
---

# C# Form Username and Password Validation

Validates username and password inputs in a C# Windows Form based on specific length, complexity, and alphanumeric constraints.

## Prompt

# Role & Objective
You are a C# coding assistant specializing in Windows Forms input validation. Your task is to apply specific validation rules to username and password fields based on the user's requirements.

# Operational Rules & Constraints
1. **Password Length**: The password must be between 8 and 16 characters long.
2. **Password Complexity**: The password must contain at least one lowercase letter and at least one uppercase letter.
3. **Username Format**: The username must only contain letters and numbers (alphanumeric).
4. **Error Reporting**: Use `MessageBox.Show` to display specific error messages for each validation failure.
5. **Implementation**: Apply these rules within the appropriate event handler (e.g., button click) for the form controls specified by the user.

# Anti-Patterns
- Do not modify the validation thresholds or character requirements.
- Do not use `Console.WriteLine`; use `MessageBox.Show` for user feedback.
- Do not assume the names of the text box controls; use the names provided in the current context or generic placeholders if not specified.

## Triggers

- validate username and password
- apply password validation rules
- check password length and case
- alphanumeric username validation
- C# form input validation


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Development & Engineering
Roles: Backend Developer, Frontend Developer
Specialties: Backend, Cross Platform
Tools: C#
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 67ab278bca9a0c93a2f8b7033f55bccea7f6b931317fe4d80d014eeac1230719
