A beautiful split-screen registration website for Silkroad Online built with Go.
- Modern split-screen design with official Silkroad Online logo
- Clean, spacious form layout with yellow/black theme
- Comprehensive validation:
- Frontend: HTML5 pattern validation with instant feedback
- Backend: Regex validation for username (alphanumeric only) and email
- Password strength requirements (minimum 6 characters)
- Password confirmation matching
- SQL Injection Protection:
- Parameterized queries (@p1, @p2, @p3)
- Input sanitization and validation
- No direct string concatenation in queries
- TLS/HTTPS Support:
- Optional TLS encryption for secure connections
- Self-signed certificate generation for development
- Production-ready with proper CA certificates
- Flexible Configuration:
- Environment variables
- Command-line flags
- Configurable database connection and server port
- Duplicate username checking
- MD5 password hashing
- Automatic security level assignment (sec_primary and sec_content set to 3)
- Fully responsive design
- Form never exceeds viewport height
- Left Panel: Beautiful background image with gradient overlay
- Right Panel: Registration form with clean, modern styling
- Mobile Responsive: Adapts to vertical layout on smaller screens
The application can be configured using environment variables or command-line flags.
Create a .env file (use .env.example as template):
# Database Configuration
DB_SERVER=localhost
DB_PORT=1433
DB_USER=sa
DB_PASSWORD=YourPasswordHere
DB_DATABASE=SRO_VT_ACCOUNT
# Server Configuration
SERVER_PORT=8080All settings can be overridden using command-line flags:
./sroreg --db-server localhost \
--db-port 1433 \
--db-user sa \
--db-password YourPassword \
--db-database SRO_VT_ACCOUNT \
--port 8080The application supports TLS/HTTPS for secure connections:
Environment Variables:
TLS_ENABLED=true
TLS_CERT=./certs/server.crt
TLS_KEY=./certs/server.keyCommand-Line Flags:
./sroreg --tls --tls-cert ./certs/server.crt --tls-key ./certs/server.keyGenerate Self-Signed Certificate (for development):
./generate-cert.shThis creates certs/server.crt and certs/server.key for testing purposes.
Running with TLS:
# Using environment variables
TLS_ENABLED=true TLS_CERT=./certs/server.crt TLS_KEY=./certs/server.key DB_PASSWORD=YourPassword go run main.go
# Using flags
go run main.go --tls --tls-cert ./certs/server.crt --tls-key ./certs/server.key --db-password YourPasswordThe server will be accessible at https://localhost:8080 (or your configured port).
For production deployments, it's recommended to use a reverse proxy like Caddy or Nginx in front of the application. This provides:
- Automatic HTTPS with Let's Encrypt
- Load balancing
- Security headers
- Access logging
Using Caddy (Recommended):
-
Copy the example Caddyfile:
cp Caddyfile.example Caddyfile
-
Edit the Caddyfile and replace
register.silkroad-example.comwith your domain -
Run the Go application on HTTP (Caddy will handle TLS):
DB_PASSWORD=YourPassword ./sroreg --port 8080
-
Start Caddy:
caddy run
Caddy will automatically:
- Obtain TLS certificates from Let's Encrypt
- Handle HTTPS connections
- Forward requests to your Go application
- Renew certificates before expiration
Using Nginx:
Example Nginx configuration:
server {
listen 80;
server_name register.silkroad-example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name register.silkroad-example.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Configuration is loaded in the following order (later overrides earlier):
- Default values (localhost:1433, port 8080)
- Environment variables
- Command-line flags
- Database: SRO_VT_ACCOUNT
- Table: dbo.TB_User
- Columns used: StrUserID, password, Email, sec_primary, sec_content
For Windows users, you can use the provided startup scripts:
Option 1: Batch File (start.bat) - Recommended for simplicity
- Double-click
start.bat - Enter your database password when prompted
- Press Enter to start the server
Option 2: PowerShell (start.ps1) - Recommended for security (masked password input)
- Right-click
start.ps1and select "Run with PowerShell" - Enter your database password when prompted (input will be hidden)
- Press Enter to start the server
Both scripts will:
- Prompt for the database password securely (no hardcoded passwords)
- Use the compiled
sroreg.exebinary if available - Fall back to
go run main.goif no binary is found - Keep the window open so you can see the server logs
Note: Before first use:
- Build the binary:
go build -o sroreg.exe main.go - Or ensure Go is installed to use
go run main.go
Security: The PowerShell script masks password input for better security, while the batch file shows the password as you type.
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envand set your database password -
Run the server:
export $(cat .env | xargs) go run main.go
go run main.go --db-password YourPassword --port 8080DB_PASSWORD=Foobarfoobar2 go run main.goThe server will start on http://localhost:8080 (or the port you configured)
The project uses GoReleaser with GitHub Actions to automatically build binaries for multiple platforms when you push a tag:
-
Create and push a new tag:
git tag -a v1.0.0 -m "Release v1.0.0" git push origin v1.0.0 -
GitHub Actions will automatically:
- Build binaries for Linux (amd64, arm64) and Windows (amd64)
- Create release archives with templates and static files included
- Generate checksums
- Create a GitHub release with all artifacts
To build manually for your current platform:
go build -o sroreg main.goTo build for a specific platform:
# Linux
GOOS=linux GOARCH=amd64 go build -o sroreg-linux-amd64 main.go
# Windows
GOOS=windows GOARCH=amd64 go build -o sroreg-windows-amd64.exe main.goEach release includes:
- Pre-compiled binaries for Linux and Windows
- All necessary templates and static files
- README and documentation
- Checksums for verification
You can replace the background image by updating static/silkroad-bg.jpg with your own Silkroad Online themed image.
sroreg/
├── main.go # Main application with database logic
├── templates/
│ └── register.html # Registration form template
├── static/
│ ├── style.css # Modern split-screen styling
│ └── silkroad-bg.jpg # Background image (can be replaced)
├── go.mod # Go module dependencies
└── README.md # This file
- User fills out the registration form with username, email, and password
- Frontend validation ensures proper input lengths
- Backend checks for duplicate usernames using StrUserID
- Password is hashed using MD5
- New user is inserted with sec_primary=3 and sec_content=3 (regular user, not admin)
- Success or error message is displayed to the user